A to-do app with 10 million users lets people set reminders such as 'call the dentist at 09:00 tomorrow' or 'every Monday at 08:30'. At the chosen time the app sends a push notification through an external push provider. Most reminders are set for round times, so thousands fall due in the same second at the top of each hour. Design the system that stores reminders and fires them within a few seconds of their due time, without sending duplicates or losing any when servers restart.
Functional requirements
Create, edit and cancel one-off and repeating reminders
Deliver a push notification within 5 seconds of the due time
Respect each user's time zone, including daylight saving changes
Retry failed deliveries and record the final outcome
Non-functional requirements
No reminder is lost once the user has saved it
Each reminder is delivered at most once per occurrence
The top-of-the-hour spike does not delay reminders by more than 5 seconds
Constraints and scale
10 million users with 50 million pending reminders
Up to 400 API requests per second to create and edit reminders
Up to 30,000 reminders due in the same minute at the top of the hour
You will practise
Store due times so the next batch can be found with an indexed range query
Hand due work to a queue so delivery scales independently of scheduling
Make delivery idempotent across retries and worker crashes
Show 2 hints
Scanning 50 million rows every second is too slow. What index lets you fetch only what is due next?
If a worker crashes after sending a push but before recording it, what stops a second send?