DEV Community

Alex Rivera
Alex Rivera

Posted on

The Midnight Reset Problem: Building Around a Clock You Do Not Control

A daily product has a clock at its centre and the clock is not yours. Midnight Eastern is a fact about the game, not about the user, and every page you cache has to decide what it means by "today".

I have been working on a companion site for a daily music puzzle, and the reset boundary has caused more bugs than any other part of the build. The naive approach is to compute the current edition from the server date at request time. That works until you cache a response, or serve the page through a CDN, or open the tab before midnight and the user comes back after it. Now you have a page that says "today" and shows yesterday.

The fix has three parts. First, the reset boundary is data, not logic: store the edition's date in the record and compute the active edition by querying for the record whose window contains the current instant. That makes the boundary explicit and testable, and it means a timezone change is a data change rather than a code change. Second, every cached page carries the edition date in the key. A page for the 21st and a page for the 22nd are different resources, even though the URL template and the layout are identical. Third, any client-side "time until reset" widget reads the server's declared window rather than the browser clock. The browser clock is wrong more often than you would think, especially on laptops that sleep.

The subtle bug is the pre-midnight open tab. If a user loads the page at 23:58 and reads it at 00:03, they see yesterday's answer labelled as today's. The cheapest mitigation is an explicit edition date on the page, in text, not just in metadata. Users can then see the mismatch themselves, and search engines can too. It costs one sentence and removes an entire class of support questions.

If you are building anything that resets, treat the reset as a first-class entity: a stored window, a dated cache key, and a visible edition label. The daily round is the test case I use, and the unlimited mode is where the ideas get stress-tested, because practice rounds are not bound to the reset calendar at all.

Top comments (0)