How does eBay end their auctions and mark the winner? Assume there is an auction end date in the database, once that time has passed the current time, the auction needs to be closed, mark the winner, etc. How is something like this handled in sql 2005? Do they query the db every second to find the expired auctions? Obviously they need to mark it as closed as soon as the auction ends. No way they are creating sql jobs for every single auction, or are they? Any ideas? I have an integration that follows a similar thought process and need help.
Obviously they need to mark it as closed as soon as the auction ends.
Yes, but not necessarily real time.
How is something like this handled in sql 2005?
Not at all. A DB is a DB. For real time pricing / auction calculation youwould use a program. Basically, update the database, but dont run the logic from the database.
Do they query the db every second to find the expired auctions?
One way. Another is to have a list ofauctions sorted by expiration in memory and just check there which expire.
No way they are creating sql jobs for every single auction, or are they?
Likely not.
What I would do is keep a list of auctions in memory. Scalability by having X auctions per server.
I would consider the state of the auction a result of the end-date of the auction and the current time. You don't have to make a change to the database in order for the state of the auction to change, the current time passing the auction end-date will do that for you.
A user viewing the auction will only view the state on a request basis, so the state can be determined at request-time. Any physical actions (sending email to winner) do not have to be true real-time. Just the closing of the bidding has to be; and the status can be determined on a per-bid basis
I had imagined that an Auction record has an attribute like EndDate
. No bids would be accepted beyond that point. When bidding, the client application would compare Now
to EndDate
. As well, the DB would check Auction.EndDate
against Now()
when attempting to log that bid.
I'm not sure that clients should be updating the auction.status="Closed"
at all. That's a dependency on a client, where perhaps the DB shouldn't have to rely on a client to 'close' an auction. Suggest that should be predetermined, and not require intervention.
My guess is a scheduler and a job/task queue where each the execution of each task is timed to coincide with the auction's exipiration. The scheduler periodically checks the queue, and when the auction's time has passed the task is executed. The task changes the auction's state to "closed," so bidding cannot occur after that poiint. That could also trigger some other actions like emailing the winner.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With