← Amazon Interview Insights

Amazon·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
May 2026

Summary

Amazon system design round for a software engineer role. The problem was building an in-memory pub-sub system from scratch, which sounds manageable until you actually have to think through thread safety and ordering guarantees at the same time.

Questions Asked (1)

Q1

Design a simplified in-memory publish-subscribe system for a single machine. It should support subscribing to topics with an integer priority, unsubscribing, and publishing messages. Messages must be delivered to subscribers in descending priority order, with earlier subscribers winning ties. The implementation must be thread-safe for concurrent operations.

System DesignTechnical Trade-offsAlgorithms & Data Structures
Author's notes

I started with the data structures and that was the right call.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then propose a high-level design using a thread-safe data structure like a concurrent map from topics to priority queues. Explain how you would handle concurrency with fine-grained locking or lock-free structures, and discuss trade-offs between simplicity and performance.

Pro tip: Demonstrate awareness of real-world concerns like lock contention and memory visibility by suggesting read-write locks or concurrent data structures, and mention how you would test for thread safety with stress tests.

1. Clarify Requirements

Ask questions to confirm scope: single machine, in-memory, thread-safe, priority ordering, tie-breaking by subscription order. Clarify if messages are delivered synchronously or asynchronously, and if subscribers can have multiple subscriptions.

2. Design Data Structures

Propose a ConcurrentHashMap<String, PriorityQueue<Subscriber>> where each topic maps to a priority queue ordered by priority (descending) and subscription time (ascending). Use a thread-safe priority queue or synchronize access.

3. Handle Concurrency

Discuss locking strategies: use per-topic locks to allow concurrent operations on different topics, or use a global lock for simplicity. Consider using ReentrantReadWriteLock for read-heavy scenarios or ConcurrentSkipListSet for lock-free ordering.

4. Implement Operations

Detail subscribe (add to queue), unsubscribe (remove from queue), and publish (iterate queue and deliver). Ensure atomicity and consistency, e.g., by locking during modification and copying the subscriber list for delivery to avoid concurrent modification.

5. Discuss Trade-offs and Extensions

Talk about performance implications, such as lock contention and scalability. Mention possible optimizations like using a lock-free queue or partitioning topics. Also consider message delivery guarantees and error handling.

Key Points to Mention

  • Thread safety mechanisms: synchronized blocks, ReentrantLock, ReadWriteLock, or concurrent collections.
  • Priority queue implementation: using a comparator that orders by priority descending and subscription time ascending.
  • Tie-breaking: ensuring earlier subscribers are served first when priorities are equal.
  • Concurrency during publish: snapshotting the subscriber list to avoid holding locks during delivery.
  • Scalability: per-topic locking to reduce contention versus global lock simplicity.
  • Testing: stress tests with multiple threads to validate thread safety and ordering.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.