Our users return to our web site from an external site, to a URL which is passed to the external site as a user leaves our site. Returning to our site involves a status update which is persisted to the application’s datastore.
I have implemented a check upon return to our web site, which prevents a multiple write to our datastore and thus makes the operation idempotent.
A typical order of events is:
- First post to our landing web page (web page instance 1 is constructing)
- First post passes check (data not processed before)
- Data persistence begins (still in the web page constructor)
- Second post to our landing web page (web page instance 2 is constructing), which is in the same session and browser window as the first post
- Second post fails check (data has been, or is being, processed already)
- Web page instance 2 constructor completes (with no persistence to datastore) and web response is served to the user
- Web page instance 1 constructor completes (after having persisted to datastore)
- The user does not see page instance 1 in their browser.
The end result is that, even though the second post is made after the first, the second post “completes” faster to the user and the user’s web browser shows instance 2 of the page, not instance 1.
My questions are:
- Is there any way I can have the first, datastore-processing, page instance shown to the user (and thus “throw away” the second page instance)?
- If so, can this be done without using AJAX?
I would appreciate any assistance greatly.
My development environment
- Web framework: Wicket 1.5.7
- Java: 1.6.0_33; Java HotSpot(TM) Client VM 20.8-b03
- Web server system: Google App Engine for Java version 1.6.6
- Operating system: Microsoft Windows XP Home Edition version 2002 SP3 (version 5.1 running on x86; Cp1252; en_GB)
- IDE: NetBeans IDE 7.1.2 (Build 201204101705)
Thank you to @svenmeier for your first tip. My solution follows this approach. I have decided to have page instance 2 wait repeatedly if necessary instead of following @Carl-EricMenzel’s suggestion of redirecting.
Referring to my order of events as set out in my question, step 6 is replaced by:
6.1 If data is being processed already, page instance 2 waits repeatedly whilst checking after each wait.
6.2 After all the waiting, page instance 1 will have completed step 7 (and 8). If not, then page instance 2 completes construction.
6.3 If the data processing of instance 1 succeeded then page instance 2 shows success to the user.
6.4 If the data processing of instance 1 failed then page instance 2 processes the data and shows the result (success/fail) to the user.