Bird
Raised Fist0
LLDsystem_design~10 mins

Notification system in LLD - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the main component responsible for sending notifications.

LLD
class Notification[1]:
    def send(self, message, user):
        pass
Drag options to blanks, or click blank then click option'
AManager
BHandler
CService
DController
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Controller' which is more related to handling user requests in MVC.
Using 'Manager' which is less common for this purpose.
2fill in blank
medium

Complete the code to add a method that queues notifications for asynchronous processing.

LLD
class NotificationService:
    def [1]_notification(self, message, user):
        # Add notification to queue
        pass
Drag options to blanks, or click blank then click option'
Aqueue
Benqueue
Csend
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' which implies immediate sending, not queuing.
Using 'push' which is less descriptive in this context.
3fill in blank
hard

Fix the error in the code to correctly process notifications from the queue.

LLD
def process_notifications():
    while not queue.[1]():
        notification = queue.get()
        notification.send()
Drag options to blanks, or click blank then click option'
AisNotEmpty
Bis_empty
Cempty
Dis_empty()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'empty' which is a property, not a method.
Using 'is_empty' without parentheses, causing syntax error.
4fill in blank
hard

Fill both blanks to define a dictionary comprehension that maps user IDs to their notification counts if count is greater than 5.

LLD
user_notifications = {user_id: count for user_id, count in notifications.items() if count [1] [2]
Drag options to blanks, or click blank then click option'
A>
B5
C<
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' which reverses the condition.
Using 10 instead of 5 which changes the threshold.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps user emails to their last notification timestamp if the timestamp is after 2023-01-01.

LLD
recent_notifications = {user[1]: notif[2] for user, notif in notifications.items() if notif[3] '2023-01-01'}
Drag options to blanks, or click blank then click option'
A.email
B.last_sent
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' which reverses the date filter.
Mixing up user and notification attributes.

Practice

(1/5)
1. Which component in a notification system is responsible for generating events that trigger notifications?
easy
A. Delivery Channel
B. Notification Service
C. User Preferences Store
D. Event Producer

Solution

  1. Step 1: Understand the role of event producers

    Event producers create or detect events that require notifying users, such as a new message or alert.
  2. Step 2: Differentiate from other components

    Notification service processes events, delivery channels send notifications, and user preferences store user settings.
  3. Final Answer:

    Event Producer -> Option D
  4. Quick Check:

    Event source = Event Producer [OK]
Hint: Event creators are called producers in notification systems [OK]
Common Mistakes:
  • Confusing notification service with event producer
  • Thinking delivery channel generates events
  • Assuming user preferences create events
2. Which of the following is the correct sequence of components for sending a notification after an event occurs?
easy
A. Delivery Channel -> Notification Service -> Event Producer
B. Event Producer -> Notification Service -> Delivery Channel
C. Notification Service -> Event Producer -> Delivery Channel
D. User Preferences Store -> Event Producer -> Delivery Channel

Solution

  1. Step 1: Identify the logical flow of notification

    First, an event is generated by the event producer, then processed by the notification service, and finally sent via the delivery channel.
  2. Step 2: Eliminate incorrect sequences

    Delivery channel cannot start the process; user preferences store is not part of the sending sequence.
  3. Final Answer:

    Event Producer -> Notification Service -> Delivery Channel -> Option B
  4. Quick Check:

    Event -> Process -> Send = A [OK]
Hint: Notifications flow from event to service to delivery [OK]
Common Mistakes:
  • Reversing the order of components
  • Including user preferences in the sending chain
  • Confusing delivery channel as event source
3. Consider a notification system where users can choose email or SMS as delivery channels. If a user prefers both, what is the expected behavior when an event triggers a notification?
medium
A. Send notification via both email and SMS
B. Send notification via email only
C. Send notification via SMS only
D. Do not send any notification

Solution

  1. Step 1: Understand user preference handling

    If a user selects multiple delivery channels, the system should send notifications through all preferred channels to ensure delivery.
  2. Step 2: Confirm expected multi-channel delivery

    Sending via both email and SMS respects user choice and increases notification reach.
  3. Final Answer:

    Send notification via both email and SMS -> Option A
  4. Quick Check:

    Multiple preferences = multiple channels [OK]
Hint: Send notifications on all user-selected channels [OK]
Common Mistakes:
  • Sending notification on only one channel
  • Ignoring user preferences
  • Not sending notification at all
4. A notification system uses a queue to handle event processing but notifications are delayed significantly. Which is the most likely cause?
medium
A. Queue is overloaded with too many events
B. User preferences are not stored
C. Delivery channel is sending notifications instantly
D. Event producer is generating too few events

Solution

  1. Step 1: Analyze queue role in notification system

    Queue buffers events to handle load. If overloaded, it causes delays in processing notifications.
  2. Step 2: Evaluate other options

    Missing user preferences or instant delivery does not cause delay; too few events would reduce load, not increase delay.
  3. Final Answer:

    Queue is overloaded with too many events -> Option A
  4. Quick Check:

    Queue overload = delay [OK]
Hint: Delays often mean queue overload, not missing data [OK]
Common Mistakes:
  • Blaming delivery channel for delays
  • Assuming missing preferences cause delay
  • Thinking fewer events cause delays
5. You need to design a notification system that supports millions of users with personalized preferences and multiple delivery channels. Which design choice best ensures scalability and user customization?
hard
A. Use a centralized notification service with a single queue and fixed delivery channels
B. Store all user preferences in a local file on the notification server
C. Implement distributed notification services with sharded queues and dynamic delivery channel selection per user
D. Send notifications synchronously from event producers directly to users

Solution

  1. Step 1: Consider scalability requirements

    Millions of users require distributed services and sharded queues to handle load without bottlenecks.
  2. Step 2: Address user customization needs

    Dynamic delivery channel selection per user allows personalized notifications respecting preferences.
  3. Step 3: Evaluate other options

    Centralized service and single queue create bottlenecks; synchronous sending blocks processing; local files do not scale or support dynamic preferences.
  4. Final Answer:

    Implement distributed notification services with sharded queues and dynamic delivery channel selection per user -> Option C
  5. Quick Check:

    Distributed + dynamic preferences = scalable & customizable [OK]
Hint: Distribute services and shard queues for scale and flexibility [OK]
Common Mistakes:
  • Choosing centralized design causing bottlenecks
  • Using synchronous sending blocking system
  • Storing preferences in non-scalable local files