Search code examples
javaarchitecturemicroservices

TimerService that will close auctions


I am developing a Vertx-Spring based Java microservice that will handle creation, updates and deletion of auctions. It will also close auctions based on a timer. What are my options on achieving this functionality? Should I use the vertx.setTimer() methods to set timer events to close such auctions?


Solution

  • You should not use a scheduled process to change the state of a resource where any time precision is needed, like an auction, because processes cannot generate events with this precision. You should also not use a service based timer to change the state of any system level resource, because you'll have a timer for every service, instead of a timer for every resource.

    Instead, when you create a new auction you should add a closed_at timestamp field. Your backend services should dynamically generate an is_closed flag such that is_closed = now() >= closed_at. This way your backend services can validate any operations against the auction (bids, cancels, etc...) and your frontend will report the state of the auction, but the closed condition will have millisecond precision and you'll never try to close the same auction twice.