0 day streak
Anonymous · shared experience20 Jun 2025 · 12 views

Razorpay: In-memory pub/sub with ordered, guaranteed per-consumer delivery

Interview question #Razorpay Machine coding

Problem. In 2 hours, with the interviewer watching your screen, build an in-memory pub/sub queue. Every message published to a topic must reach every subscriber of that topic, in publish order.

Features. Create topics; publish; subscribe and unsubscribe; several consumers per topic; track each consumer's progress on each topic; keep order per consumer; let consumers filter messages; define what happens while a consumer is offline.

Clarifications given. String payloads with metadata for filtering. Filters are simple key-value matches. Keep messages for offline consumers in memory with no time limit. Start single-threaded.

Follow-ups.

  • How would you make it thread-safe? (One lock per topic, not one global lock.)
  • A topic holds millions of messages and a subscriber has been offline for a week. What happens to memory?
  • A consumer crashes after reading a message but before processing it. How do you still guarantee delivery?

Focus. Clarifying first, data-structure trade-offs, a driver that proves the behaviour, and readable code.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.