Design Idempotent In-App Availability and Due-Date Notifications
InstacartSoftware Engineer · Online AssessmentLast updated
Design asynchronous in-app availability alerts and due-date reminders with Celery, Redis, durable idempotency, versioned schedules, and crash recovery.
Add a notification service to an existing web application. It must provide in-app notifications when an item becomes available and reminders related to an item's due date. Use Celery and Redis for asynchronous processing, and address idempotency and edge cases.
Begin by eliciting the detailed requirements, then propose a design that can be implemented and tested. No specific database, reminder offset, delivery deadline, or item schema is prescribed.
Constraints & Assumptions
- The required delivery channel is the application's in-app notification feed.
- Availability notifications and due-date reminders are distinct notification types.
- Practice clarification: assume users can subscribe to an item, an availability transition can be identified, and a due date can change or be removed. Explain any additional data fields you introduce.
- Workers can retry or restart. Do not assume that a task is executed only once.
Clarifying Questions to Ask
- Does every unavailable-to-available transition generate a new notification, or only the first transition for a subscription?
- What is the reminder offset, which time zone defines a due date, and what happens if a due date is changed after a reminder was scheduled?
- Should unsubscribing cancel pending notifications? Should already delivered notifications remain visible?
- Is a missed reminder still useful after its scheduled time or after the due date?
Hints
Hint 1
Separate work delivery from notification creation: A task can arrive more than once without requiring more than one visible notification. Decide where the durable uniqueness decision belongs.
Follow-up questions
- What happens if a worker commits the notification and crashes before acknowledging the task?
- How would a changed due date invalidate old reminder tasks without relying on deleting every queued message?
- How would you recover notification work if a database transaction committed but publishing to Redis failed?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.