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.
Depending on the scale of your project you may get away with a single SQL job that performs mass closing of the auctions. Run this every minute.
Update [Auctions] SET AuctionStatus = 'CLOSED' WHERE CloseDate <= CURRENT_TIMESTAMP;
Have your application logic only post bids to auctions where this same where clause is met.
You can then process auction winners with another scheduled job and runs against closed auctions that are not yet processed.
First thing that pops into my head is a javascript function that is called when the auction countdown timer reaches a certain number, in this case I would imagine 0. Have the function make a ajax call to a script, which would verify that the auction has indeed expired, then update the database.
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.