Bird
Raised Fist0
HLDsystem_design~20 mins

One-to-one messaging in HLD - Practice Problems & Coding Challenges

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
Challenge - 5 Problems
🎖️
One-to-One Messaging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Architecture
intermediate
2:00remaining
Design Components for One-to-One Messaging

Which component is essential to ensure message delivery confirmation in a one-to-one messaging system?

ALoad Balancer to distribute incoming messages evenly
BCache Layer to store user profiles temporarily
CMessage Queue to store and forward messages reliably
DAnalytics Module to track message read rates
Attempts:
2 left
💡 Hint

Think about how to guarantee messages are not lost and are delivered even if the receiver is offline.

scaling
intermediate
2:00remaining
Scaling User Connections in One-to-One Messaging

What is the best approach to handle millions of simultaneous user connections in a one-to-one messaging system?

AImplement horizontal scaling with multiple servers and sticky sessions
BUse client polling every second to check for new messages
CStore all messages in a single database instance
DUse a single centralized server with multi-threading
Attempts:
2 left
💡 Hint

Consider how to distribute load and maintain user session consistency.

tradeoff
advanced
2:00remaining
Tradeoff Between Consistency and Availability

In a one-to-one messaging system, choosing between strong consistency and high availability during network partitions is a challenge. Which option best describes this tradeoff?

AFavor consistency by blocking message delivery until all replicas confirm receipt
BFavor availability by allowing messages to be delivered even if some replicas are out of sync
CIgnore network partitions and continue normal operations
DUse a single database to avoid replication issues
Attempts:
2 left
💡 Hint

Think about user experience during network issues and how message delivery should behave.

🧠 Conceptual
advanced
2:00remaining
Message Ordering Guarantees

Which design choice ensures strict message ordering in a one-to-one messaging system?

ADeliver messages as soon as they arrive without buffering
BStore messages in multiple shards without coordination
CUse eventual consistency for message storage
DAssign a unique, incrementing sequence number to each message per conversation
Attempts:
2 left
💡 Hint

Consider how to keep track of the order in which messages are sent and received.

estimation
expert
3:00remaining
Capacity Estimation for One-to-One Messaging

Estimate the storage needed per day for a one-to-one messaging system with 10 million active users, each sending 50 messages daily. Assume average message size is 1 KB.

AApproximately 500 GB per day
BApproximately 5 TB per day
CApproximately 50 TB per day
DApproximately 500 TB per day
Attempts:
2 left
💡 Hint

Calculate total messages and multiply by average message size.

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