KatInterview

Build a Retry-Safe Task Scheduler for Event Notifications

System DesignModel answer
MediumModel answerSystem Designasync-tasksidempotencydistributed-systems

Last updated

Design an async notification system for item availability and due-date reminders with durable idempotency and crash recovery.

You're building a notification subsystem for an existing web platform. The system needs to send two kinds of alerts through the application's internal notification feed:

  1. Availability alerts: when a previously unavailable item becomes available
  2. Due-date reminders: alerts sent before an item's deadline

The platform already has items, users, and a subscription mechanism. Your task is to design the notification layer using Celery for task execution and Redis for coordination.

What You Need to Address

  • How do you model subscriptions, notification state, and scheduled work?
  • How do you ensure exactly-once delivery when workers crash and retry?
  • How do you handle due-date changes after a reminder is already scheduled?
  • How do you prevent stale or duplicate notifications?

Platform Assumptions

  • Users can subscribe to items
  • You can detect when an item transitions from unavailable to available
  • Due dates can be updated or removed after being set
  • Celery workers may crash, restart, or execute the same task multiple times

Questions to Explore Before Designing

Before presenting your design, clarify:

  • Should every availability transition trigger a new notification, or only the first one per subscription?
  • What offset should reminders use (e.g., 24 hours before due date)? Which timezone applies?
  • If a due date changes after scheduling a reminder, should the old reminder be canceled?
  • When a user unsubscribes, should pending notifications be canceled? Should delivered ones remain visible?
  • Is a late reminder (delivered after its target time or after the due date) still valuable?

Present a design that includes the data model, the task execution flow, idempotency enforcement, and how you handle the edge cases above. Explain how you would test crash scenarios and concurrent task execution.

Hints

Hint 1

Think about how to uniquely identify each notification intent so duplicates can be detected

Hint 2

Consider versioning due dates so you can detect when a scheduled reminder is based on stale information

Hint 3

Design the idempotency check as a database constraint or atomic operation, not just application logic