What if you never had to ask "Are you free?" again to start a quick chat?
Why Online presence system in HLD? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine a small team trying to know who is available for a quick chat by manually asking each member every time they want to talk.
They send messages or call one by one, wasting time and missing chances to connect quickly.
This manual way is slow and frustrating.
People forget to update their status, messages get lost, and the team loses track of who is free or busy.
It causes delays and confusion, especially as the team grows.
An online presence system automatically shows who is online, busy, or away in real time.
It updates statuses instantly and shares this info with everyone, so team members can connect at the right time without asking.
Send message: "Are you free?" Wait for reply.
Show status: 'Online' or 'Busy' instantly to all team members.
It enables seamless, instant awareness of team availability, making communication faster and smoother.
In a remote work setup, an online presence system helps coworkers see who is available for a quick call or collaboration without interrupting others unnecessarily.
Manual checking wastes time and causes confusion.
Online presence systems update availability automatically and instantly.
This improves team communication and productivity.
Practice
Solution
Step 1: Understand the role of presence system
An online presence system tracks user activity to know if they are online or offline.Step 2: Differentiate from other chat features
Message storage, encryption, and password management are separate features not handled by presence systems.Final Answer:
To track if users are currently online or offline -> Option AQuick Check:
Presence system = user online status [OK]
- Confusing presence with message storage
- Thinking presence handles security features
- Mixing presence with account management
Solution
Step 1: Identify presence tracking events
Presence systems useconnect,heartbeat, anddisconnectto track user activity.Step 2: Recognize unrelated events
message_sendrelates to sending chat messages, not presence tracking.Final Answer:
message_send-> Option AQuick Check:
Presence events exclude message sending [OK]
- Assuming message events track presence
- Confusing heartbeat with message_send
- Ignoring disconnect event importance
user_last_seen = 0
current_time = 10
heartbeat_interval = 5
if current_time - user_last_seen <= heartbeat_interval:
status = 'online'
else:
status = 'offline'Solution
Step 1: Calculate time difference
current_time - user_last_seen = 10 - 0 = 10 seconds.Step 2: Compare with heartbeat interval
10 <= 5 is false, so status is set to 'offline'.Final Answer:
"offline" -> Option CQuick Check:
Time diff > heartbeat means offline [OK]
- Mixing up less than and greater than
- Forgetting to subtract last seen time
- Assuming status is always online
def update_status(last_seen, current_time, heartbeat=10):
if current_time - last_seen > heartbeat:
return 'online'
else:
return 'offline'Solution
Step 1: Analyze the condition meaning
If time difference is greater than heartbeat, user should be offline, not online.Step 2: Correct the comparison
The condition should return 'offline' when difference > heartbeat, so the comparison sign must be reversed.Final Answer:
The comparison sign should be reversed -> Option BQuick Check:
Time diff > heartbeat means offline [OK]
- Returning online when user is inactive
- Misunderstanding heartbeat meaning
- Ignoring return type correctness
Solution
Step 1: Evaluate centralized database approach
Querying a centralized DB for every request causes high latency and bottlenecks at scale.Step 2: Consider distributed cache with TTL and heartbeats
This approach keeps presence data fresh, reduces DB load, and supports real-time updates efficiently.Step 3: Analyze other options
Ignoring heartbeats or updating once per day leads to stale presence info, unsuitable for real-time apps.Final Answer:
Use distributed in-memory cache with TTL and heartbeat updates from clients -> Option DQuick Check:
Distributed cache + heartbeat = scalable real-time presence [OK]
- Relying on centralized DB for real-time presence
- Ignoring heartbeat updates causing stale data
- Updating presence too infrequently
