Bird
Raised Fist0
HLDsystem_design~10 mins

One-to-one messaging in HLD - 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 identify the main component responsible for storing messages.

HLD
The core component for storing messages in one-to-one messaging is the [1].
Drag options to blanks, or click blank then click option'
ALoad Balancer
BMessage Queue
CDatabase
DCache
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing message queue with permanent storage
Choosing cache as the main storage
2fill in blank
medium

Complete the code to specify the component that balances incoming message requests.

HLD
To distribute incoming message requests evenly, the system uses a [1].
Drag options to blanks, or click blank then click option'
ADatabase
BCache
CMessage Broker
DLoad Balancer
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing database instead of load balancer
Confusing message broker with load balancer
3fill in blank
hard

Fix the error in the message delivery flow by choosing the correct component that ensures message delivery to the recipient.

HLD
After storing the message, the system uses a [1] to deliver the message to the recipient in real-time.
Drag options to blanks, or click blank then click option'
ALoad Balancer
BMessage Broker
CPush Notification Service
DDatabase
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing database for delivery instead of message broker
Confusing push notification service with message broker
4fill in blank
hard

Fill both blanks to complete the code describing message storage and retrieval.

HLD
Messages are stored in a [1] and retrieved using a [2] to ensure fast access.
Drag options to blanks, or click blank then click option'
ADatabase
BCache
CLoad Balancer
DMessage Broker
Attempts:
3 left
💡 Hint
Common Mistakes
Using load balancer as storage
Confusing message broker with cache
5fill in blank
hard

Fill all three blanks to complete the code describing the message flow from sender to recipient.

HLD
Sender sends message to [1], which stores it in [2] and then [3] delivers it to the recipient.
Drag options to blanks, or click blank then click option'
ALoad Balancer
BDatabase
CMessage Broker
DCache
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up delivery and storage components
Choosing cache instead of database for storage

Practice

(1/5)
1. What is the primary role of the server in a one-to-one messaging system?
easy
A. To allow users to send messages directly without any intermediary
B. To store all messages permanently without delivering them
C. To receive messages from the sender and deliver them to the receiver
D. To broadcast messages to all users in the system

Solution

  1. Step 1: Understand message flow in one-to-one messaging

    Messages are sent from one user to another through a server acting as an intermediary.
  2. Step 2: Identify server's role

    The server receives messages from the sender and forwards them to the intended receiver, ensuring delivery and possibly storing temporarily.
  3. Final Answer:

    To receive messages from the sender and deliver them to the receiver -> Option C
  4. Quick Check:

    Server acts as message relay = B [OK]
Hint: Server relays messages between users, not direct connection [OK]
Common Mistakes:
  • Thinking users connect directly without server
  • Assuming server only stores without forwarding
  • Confusing one-to-one with broadcast messaging
2. Which component is essential to ensure message privacy in a one-to-one messaging system?
easy
A. End-to-end encryption
B. Message queue
C. Load balancer
D. Caching layer

Solution

  1. Step 1: Identify privacy needs in messaging

    Privacy means only sender and receiver can read the message content.
  2. Step 2: Match privacy solution

    End-to-end encryption encrypts messages so only sender and receiver can decrypt them, ensuring privacy.
  3. Final Answer:

    End-to-end encryption -> Option A
  4. Quick Check:

    Privacy needs encryption = C [OK]
Hint: Privacy means encrypt messages end-to-end [OK]
Common Mistakes:
  • Confusing load balancer as privacy tool
  • Thinking caching secures messages
  • Assuming message queue provides privacy
3. Consider this simplified message flow code snippet for one-to-one messaging:
def send_message(sender, receiver, message):
    server.store_message(sender, receiver, message)
    server.deliver_message(receiver)

send_message('Alice', 'Bob', 'Hello')
What is the expected output or result of this code?
medium
A. Syntax error due to missing parameters
B. Message is delivered to Alice instead of Bob
C. Message is stored but never delivered
D. Message 'Hello' is stored and delivered to Bob

Solution

  1. Step 1: Analyze function calls

    The function stores the message from Alice to Bob, then delivers it to Bob.
  2. Step 2: Check message flow correctness

    Message is stored correctly and delivery is triggered for Bob, the intended receiver.
  3. Final Answer:

    Message 'Hello' is stored and delivered to Bob -> Option D
  4. Quick Check:

    Store then deliver to receiver = D [OK]
Hint: Store then deliver to receiver means message sent correctly [OK]
Common Mistakes:
  • Confusing sender and receiver in delivery
  • Assuming message is not delivered after storing
  • Thinking code has syntax errors
4. In a one-to-one messaging system, this code snippet causes messages to never reach the receiver:
def deliver_message(receiver, message):
    if receiver.is_online == False:
        return
    send_to_client(receiver, message)
What is the main issue causing message delivery failure?
medium
A. The function sends messages to the wrong user
B. Messages are dropped if receiver is offline without queuing
C. There is a syntax error in the if condition
D. The message variable is undefined

Solution

  1. Step 1: Understand delivery condition

    The function returns early if the receiver is offline, skipping delivery.
  2. Step 2: Identify missing handling

    Messages are not queued or stored for later delivery, so offline users never get messages.
  3. Final Answer:

    Messages are dropped if receiver is offline without queuing -> Option B
  4. Quick Check:

    Offline receiver drops messages = A [OK]
Hint: Offline users need message queue to avoid drops [OK]
Common Mistakes:
  • Thinking syntax error causes failure
  • Assuming wrong user receives message
  • Assuming offline messages are automatically queued
5. You are designing a scalable one-to-one messaging system for millions of users. Which approach best ensures message delivery even if the receiver is offline?
hard
A. Use a message queue to store undelivered messages and retry delivery when receiver is online
B. Drop messages if receiver is offline to save storage and bandwidth
C. Broadcast messages to all users and let receiver filter them
D. Send messages only when both users are online simultaneously

Solution

  1. Step 1: Understand offline delivery challenge

    Receivers may be offline, so messages must be stored to avoid loss.
  2. Step 2: Choose scalable solution

    Message queues store undelivered messages and retry delivery when receiver reconnects, ensuring reliability and scalability.
  3. Final Answer:

    Use a message queue to store undelivered messages and retry delivery when receiver is online -> Option A
  4. Quick Check:

    Queue undelivered messages for offline users = A [OK]
Hint: Queue messages for offline users to ensure delivery [OK]
Common Mistakes:
  • Dropping messages loses data
  • Broadcast wastes resources and breaks privacy
  • Requiring both online limits usability