Course contentsShow
← System Design
Lesson 1723 of 1,91941. Real-World System: Notification SystemFree lesson

Quiet Hours and Time-Zone Handling

Respect user-defined quiet hours by storing timezone preferences and delaying notification delivery appropriately.

Quiet Hours and Time-Zone Handling

What you'll learn: How to respect user sleep schedules by storing timezone preferences and intelligently delaying notifications to avoid disturbing users at inappropriate times.

The Core Challenge

Imagine sending a promotional notification at 3 AM to a user in Tokyo because your servers are in California. Respecting quiet hours means understanding when it is for each user, not just when it is for your system. This requires storing timezone data and implementing delivery delays that honor user-defined "do not disturb" windows.

How It Works

When a user sets quiet hours (e.g., "10 PM - 7 AM"), you store:

  • Their timezone (America/New_York, Asia/Tokyo)
  • Their quiet start and end times in local format
  • Optional per-channel overrides (maybe allow SMS in emergencies)

Before dispatching a notification, the system:

  1. Converts the current UTC time to the user's local timezone
  2. Checks if local time falls within their quiet hours
  3. If yes, calculates the next acceptable delivery time (e.g., 7:01 AM their time)
  4. Schedules the notification for delayed delivery using a priority queue or scheduled task worker

Implementation Considerations

Store timezone as IANA timezone identifiers (America/Los_Angeles), not just UTC offsets, because offsets change with daylight saving time. Your notification workers need timezone-aware libraries to perform conversions correctly.

For delayed delivery, enqueue the notification with a scheduled_for timestamp. Workers skip messages whose delivery time hasn't arrived yet, re-queuing them for later processing.

Key Takeaway:
Respecting quiet hours requires storing user timezone preferences, converting system time to local user time, and scheduling notification delivery to fall outside user-defined do-not-disturb windows.