Sample questions
Question 1Easy
For one-to-one chat delivered in real time to online users, the client usually keeps:
- A new HTTP request every 10 ms
- An FTP session
- An SMTP connection
- A persistent WebSocket (or similar) connection
Answer: D. A persistent WebSocket (or similar) connection
Explanation
Long-lived bidirectional connections let the server push messages instantly.
Step-by-step solution
- Real-time chat needs the server to push messages to an online user instantly.
- A plain HTTP request cannot be pushed by the server without the client asking.
- A persistent connection, such as a WebSocket, lets the server push at any time.
- So the answer is option D.
Why the other options are wrong
- A. Polling every 10 milliseconds is wasteful and still not a push model.
- B. FTP is for file transfer, not chat.
- C. SMTP is for sending email, not real-time chat.
Tip: For server push to online clients, use a persistent connection such as a WebSocket.
Question 2Easy
If a chat recipient is offline, the system should:
- Store the message and send a push notification
- Email the sender an error
- Drop the message
- Keep retrying the WebSocket forever
Answer: A. Store the message and send a push notification
Explanation
Messages persist for later sync, and a push notification alerts the user's device.
Step-by-step solution
- An offline recipient cannot receive the message in real time.
- The system stores the message so it can sync when the user returns.
- A push notification alerts the user's device that there is a new message.
- So the answer is option A.
Why the other options are wrong
- B. The sender should not get an error; the message is still delivered later.
- C. Dropping the message loses it.
- D. Retrying a WebSocket forever wastes resources; the offline user is not connected.
Tip: For offline users, persist the message and notify through a push channel.
Question 3Easy
A notification system sends email, SMS and push. Why put a queue per channel?
- Queues guarantee instant delivery to every device, even when it is offline
- To store user passwords
- So each channel scales and fails independently
- Queues make SMS free
Answer: C. So each channel scales and fails independently
Explanation
A slow SMS provider should not delay push notifications; separate queues and workers isolate them.
Step-by-step solution
- Email, SMS and push each have their own provider, speed and failure mode.
- If they share one queue, a slow SMS provider can delay push notifications.
- A queue per channel with its own workers lets each scale and fail alone.
- So the answer is option C.
Why the other options are wrong
- A. Queues do not guarantee delivery to offline devices.
- B. Queues are not for storing passwords.
- D. Queues do not make SMS free; SMS providers still charge.
Tip: Isolate channels with separate queues so one slow provider cannot block the others.
Question 4Easy
Where are feed images and videos best stored and served from?
- Inside the relational database as BLOBs
- Object storage behind a CDN
- In the message queue
- On each app server's local disk
Answer: B. Object storage behind a CDN
Explanation
Object storage is cheap and durable; the CDN serves media close to users.
Step-by-step solution
- Images and videos are large, and they must be stored durably and cheaply.
- Object storage is built for that, and a CDN serves copies close to users.
- Putting media in the relational database or app servers is costly and does not scale.
- So the answer is option B, object storage behind a CDN.
Why the other options are wrong
- A. Storing large media as database BLOBs is costly and slow.
- C. A message queue is not storage for media.
- D. App server disks are not durable or shared across servers.
Tip: Store media in object storage and serve it through a CDN; keep only references in the database.
Question 5Medium
Why is a unique ID generator like Snowflake preferred over UUIDv4 for some databases?
- They need no clock
- They are cryptographically secret, so users cannot guess the next ID
- IDs are roughly time-ordered, which suits B-trees
- They are always shorter strings
Answer: C. IDs are roughly time-ordered, which suits B-trees
Explanation
Sequential-ish keys append to the index; random UUIDs scatter inserts across pages.
Step-by-step solution
- A B-tree index is faster when new keys arrive in roughly increasing order.
- Snowflake IDs are roughly time-ordered, so inserts go to the end of the index.
- Random UUIDv4 values scatter inserts across many pages.
- So the answer is option C.
Why the other options are wrong
- A. Snowflake-style IDs still use a clock; that is how they get time order.
- B. Snowflake IDs are not secret; ordering is the benefit, not secrecy.
- D. Snowflake IDs are not always shorter; the length is fixed by design.
Tip: Time-ordered IDs keep B-tree inserts local; fully random keys cause page splits and scattered writes.
Question 6Medium
How can a file storage service let clients upload directly to object storage without proxying bytes through app servers?
- Make the bucket publicly writable
- Issue a short-lived pre-signed upload URL
- Ask clients to email files to support
- Share the storage account's root keys with clients
Answer: B. Issue a short-lived pre-signed upload URL
Explanation
Pre-signed URLs grant time-limited permission for one object, keeping credentials private and app servers out of the data path.
Step-by-step solution
- The app server would otherwise carry every byte of the upload.
- A pre-signed URL grants permission to upload one object for a short time.
- The client uploads straight to object storage, and the app server stays out of the data path.
- So the answer is option B.
Why the other options are wrong
- A. A publicly writable bucket lets anyone write to it.
- C. Emailing files does not use storage at all.
- D. Sharing root keys gives clients full access and is unsafe.
Tip: Use short-lived, single-object pre-signed URLs so clients never hold storage credentials.
Question 7Medium
Which feature should a notification system include to respect users?
- Ignoring time zones
- Sending every event on every channel
- Per-user preferences, opt-outs and rate limits
- Retrying forever on hard bounces
Answer: C. Per-user preferences, opt-outs and rate limits
Explanation
Preferences, quiet hours and caps prevent spam and regulatory issues.
Step-by-step solution
- A good notification system should not spam users.
- It should respect time zones, quiet hours, channel choices and opt-outs.
- Per-user preferences, opt-outs and rate limits give that control.
- So the answer is option C.
Why the other options are wrong
- A. Ignoring time zones can send messages at night to users.
- B. Sending every event on every channel causes spam.
- D. Retrying forever on hard bounces wastes sends and can break provider limits.
Tip: Build preferences, opt-outs and caps in from the start, not as an afterthought.
Question 8Medium
Why might a URL shortener prefer 302 over 301 redirects?
- 302 is faster for browsers
- Browsers cache 301s, so later clicks skip the service
- 302 makes URLs shorter because the code can be reused after expiry
- 301 does not work on mobile
Answer: B. Browsers cache 301s, so later clicks skip the service
Explanation
With a permanent redirect the browser may never call the service again, losing click counts.
Step-by-step solution
- A 301 is permanent, so browsers may cache it and skip the shortener on later clicks.
- A 302 is temporary, so each click comes back to the service.
- The service can then count every click.
- So the answer is option B.
Why the other options are wrong
- A. 302 is not faster; the reason to use it is the click count.
- C. Expiry has nothing to do with 301 versus 302, and 302 does not make URLs shorter.
- D. 301 works on mobile browsers; this is not the reason.
Tip: Use 301 only when caching is wanted; use 302 when every click must reach your servers.
Question 9Hard
Why do feed systems often use a hybrid of fan-out-on-write and fan-out-on-read?
- Hybrid removes the need for caching
- Fan-out-on-write cannot handle images or videos, so media posts must be pulled
- Fan-out-on-read is always faster
- Pushing a celebrity's post to millions is too costly
Answer: D. Pushing a celebrity's post to millions is too costly
Explanation
Normal users' posts are pushed; posts from accounts with huge follower counts are merged in when followers read.
Step-by-step solution
- Fan-out-on-write for an account with millions of followers means millions of writes per post.
- That is too costly for very large accounts.
- A hybrid pushes normal users' posts and merges celebrity posts in at read time.
- So the answer is option D.
Why the other options are wrong
- A. A hybrid still uses caching; it only changes how feeds are built.
- B. Fan-out-on-write does not depend on media type.
- C. Fan-out-on-read is not always faster; it costs more work at read time.
Tip: Hybrid feeds push posts from normal accounts and pull posts from accounts with huge follower counts.
Question 10Hard
A leaderboard needs top-100 scores updated in real time for millions of players. A good fit is:
- A Redis sorted set
- A relational table with ORDER BY on every request
- A CDN cache with a 1-day TTL
- A message queue
Answer: A. A Redis sorted set
Explanation
Sorted sets keep members ordered by score with O(log n) updates and fast range queries.
Step-by-step solution
- A leaderboard needs the top scores kept in order as scores change.
- A Redis sorted set keeps members ordered by score with fast updates.
- Range queries for the top 100 are fast from a sorted set.
- So the answer is option A.
Why the other options are wrong
- B. ORDER BY on every request re-sorts the data each time and is slow at this scale.
- C. A CDN with a 1-day TTL would show stale scores.
- D. A message queue stores events in order, but it does not give ranked top-100 queries.
Tip: For a live top-N ranking, use a sorted set keyed by score.
Practise all 27 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →