Team AdWeb has worked for a distinctive list of industries counting from hospitability to technology and retailers to an online lottery purchase system based website. Yes, we recently collaborated with a Japan-based company to build their website with lottery purchase system, using Drupal 8. We’ve been Drupal-ing even before our inception and have been an active member of the Drupal community, globally. Our association and experience of Drupal were the base of the client’s immense faith in us and we knew that we’re going to stand true to that.
About the Project
The project requirement of the client was to build a website for them in Drupal 8. The website is basically an online lottery purchase system. Due to confidential reasons, we can not share the name of the company/client but would like to share that the experience of working on this project was new and enriching.
Major Features/Functionalities
We personally love experimenting and implementing innovative features to enhance the client’s website. Plus, we get a little more excited when its a Drupal 8 website. We integrated a host of futuristic features to this very website too. But since, it’s an online lottery purchase system we knew that the integration of the Payment Gateway is going to be one of an integral part. Hence, we created three types of Payment Gateway, as follows:
GMO Payment
Coins Payment
WebMoney Payment
The user is an integral part of this entire online lottery system and hence several functionalities are crafted around them. Like, a user can purchase coins by WebMoney Payment method and can also buy lottery from choosing any product bundle. A user also has an option to select the quantity of the product or go for the complete set. The payment for either of it can be done by the coins, GMO credit card or points.
Draw system is used for the selection of the lottery winner. Other than the lottery prize, the user also stands a chance to win the Kiriban Product as a prize. The Kiriban Product is based on the product bundle configuration, which is an additional product that a user gets as defined by an admin user.
The Problem
Any e-commerce website will definitely have multiple users buying for the same product. In this situation, the backend technicalities should be as such that it updates the quantity left of the product after the last purchase is made. Issues occur when two or more users place the order at the same time. This is an issue that is involved in concurrent shopping. In this case, the lottery opened for some specific time. Hence, the issue occurred in showcasing the updated quantity. This problem came to our notice when the site went live and around 7-8 users made the transaction at one specific time. We immediately started working on the issue.
Challenges Faced:
We quickly picked up the problem and started searching for the resolution. We have had several times, prior to this, created an e-commerce website. Hence, we used multiple methods to resolve the issues, mentioned below, but none of them worked in this particular case.
Initially, we tried using a Drupal lock to resolve the issue, but in vain.
We, later on, used the MySQL lock but this too didn’t work, due to the involvement of multiple quantities inside for loop.
The usage of sleep time with random sleep time also did not work, because it created the nearby value and not the exact one.
Though the method of random sleep time did not work in this case, it gave birth to the final resolution that worked. And hence, we did a minor modification to the same and divided the sleep time in a range of 3. Also, to avoid the possibility of any further clash, we adopted a table of 100.
The Final Resolution:
After trying out a handful of methods, we finally came up with a method that did work out in our favor. Let us share what steps did finally help us in addressing the problem of concurrent shopping that we faced:
A table consisting of 1 to 100 numbers was taken, with the sleep time by a range of 3.
Later, a random number was picked and a flag value for the same was set
Then, a greater number from those numbers with the range of 3 was picked
Below is the table that was created to bring out the final solution:
,
,
‘Flag’ was used to 0 by default, which will be automatically set to 1 every time the number is in use
How it works:
At the beginning of the transaction, the max sleep_time will be checked where flag=1
The sleep_time for the first user will be 0
After this, a random number from max sleep_time is selected with a range of 3
The first user’s range is 1-3
In the case of the second user, one number will be skipped after the max time and will be started after that number
In case a user gets the max sleep_time in 3 then the range for the random number will be 5-7
If the second user gets the random number as 6 then the random number range for the third user will be 8-10
The flag value will be updated as 1 for this random number
In the end, the flag value of the transaction will be updated with 0
The Final Say:
“All is well, that ends well.” And that’s exactly we have to say for this particular project. Yes, though we had coded and created many e-commerce websites before, this was the first time that we picked up a project to create a Drupal 8 website with an online lottery system. And believe us, it was a monumental success for us and satisfying project for the client.