← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Snapchat SWE interview that was basically a systems design session dressed up as a coding round. Started with a clean pub/sub implementation and then kept layering on follow-ups until we were deep in concurrency territory. Pretty solid interview if you like that kind of incremental design problem.

Questions Asked (3)

Q1

Design and implement an in-memory Pub/Sub system with createTopic, subscribe, and publish operations.

System DesignAlgorithms & Data Structures
Author's notes

The base implementation wasn't too bad.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: in-memory, single-process, thread-safe, and expected scale. Then design a simple yet extensible architecture using a map of topics, each with a list of subscribers, and implement publish to iterate over subscribers and deliver messages. Discuss trade-offs like synchronous vs asynchronous delivery, backpressure, and concurrency control.

Pro tip: Show awareness of real-world concerns: mention that Snapchat's scale would require distributed pub/sub, but for in-memory you'd focus on thread safety and efficient delivery. Also, propose a simple API and test cases to validate behavior.

1. Clarify Requirements

Ask about expected number of topics, subscribers per topic, message throughput, delivery guarantees (at-most-once, at-least-once), and whether persistence or ordering is needed.

2. Design Data Structures

Propose a Topic class holding a list of subscribers, and a PubSubSystem class with a map from topic name to Topic. Consider using concurrent data structures for thread safety.

3. Implement Core Operations

Implement createTopic to add a new topic, subscribe to add a subscriber to a topic, and publish to iterate over subscribers and deliver the message (e.g., via callback).

4. Address Concurrency and Delivery

Discuss thread safety: use locks or concurrent collections. Decide on synchronous vs asynchronous delivery, and handle slow subscribers (e.g., queues, backpressure).

5. Test and Extend

Outline unit tests for basic operations and edge cases. Mention possible extensions like wildcard subscriptions, message filtering, or persistence.

Key Points to Mention

  • Thread safety: use ConcurrentHashMap for topics and CopyOnWriteArrayList for subscribers, or synchronize critical sections.
  • Delivery semantics: synchronous vs asynchronous, and how to handle slow consumers (e.g., bounded queues, dropping messages).
  • Scalability: in-memory limits, and how the design would change for distributed systems (e.g., using Kafka, Redis Pub/Sub).
  • API design: clear method signatures, error handling (e.g., topic already exists, subscriber not found).
  • Message ordering: whether messages are delivered in order per subscriber, and how to guarantee it.
  • Resource management: unsubscribing, deleting topics, and preventing memory leaks.

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

Q2

Modify the publish method so subscribers receive messages via push delivery instead of polling, using callbacks or per-subscriber queues.

System DesignTechnical Trade-offsAPI & Integrations
Author's notes

This is where it got more interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the current publish method and subscriber model, then propose a push-based design using callbacks or per-subscriber queues. Discuss trade-offs like backpressure, delivery guarantees, and scalability, and outline how you would implement and test the change.

Pro tip: Emphasize idempotency and backpressure handling—Snapchat deals with massive scale, so showing awareness of these concerns will set you apart. Also, mention that you'd consider a hybrid approach if some subscribers still need polling.

1. Clarify Requirements and Current Design

Ask questions to understand the existing publish method, subscriber interface, and constraints (e.g., message ordering, delivery guarantees). Identify why polling is used and what push delivery should achieve.

2. Choose Push Mechanism

Decide between callbacks (direct invocation) and per-subscriber queues (decoupled). Consider factors like subscriber count, message volume, and failure isolation.

3. Design for Scalability and Reliability

Address backpressure, retries, dead-letter queues, and idempotency. Ensure the system can handle slow or failing subscribers without affecting others.

4. Implement and Integrate

Modify the publish method to enqueue messages or invoke callbacks. Update subscriber registration to provide callback or queue endpoints.

5. Test and Validate

Write unit and integration tests for delivery, failure scenarios, and performance. Compare metrics (latency, throughput) with the polling approach.

Key Points to Mention

  • Callback vs. queue trade-offs: callbacks are simple but can block; queues decouple but add complexity.
  • Backpressure handling: bounded queues, dropping messages, or applying flow control.
  • Delivery guarantees: at-least-once vs. at-most-once, and idempotent message processing.
  • Scalability: per-subscriber queues can be distributed; callbacks may need thread pools.
  • Error handling: retries, dead-letter queues, and monitoring for failed deliveries.
  • Migration strategy: gradual rollout, feature flags, and fallback to polling if needed.

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

Q3

How would you handle concurrent publishers and subscribers in this system? Walk through a mutex-based approach and then explain how a read/write lock improves throughput.

System DesignTechnical Trade-offs
Author's notes

No code needed here, just verbal design, which I actually appreciated.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the problem: multiple threads or processes publishing and subscribing concurrently, requiring synchronization to avoid race conditions. Then walk through a mutex-based solution, highlighting its simplicity and limitations (serialized access). Finally, introduce a read/write lock, explaining how it allows concurrent reads (subscribers) while writes (publishers) remain exclusive, thus improving throughput.

Pro tip: Mention that read/write locks are not a silver bullet: they add overhead and can cause writer starvation; consider using a fair lock or a read-copy-update (RCU) mechanism for read-heavy workloads. This shows you understand trade-offs beyond the textbook answer.

1. Clarify the concurrency model

Ask or state assumptions about the system: are publishers and subscribers threads in the same process, or separate processes? What is the expected read/write ratio? This sets the stage for choosing the right synchronization primitive.

2. Mutex-based approach

Describe using a single mutex to protect the shared data structure (e.g., a queue or topic list). Publishers and subscribers must acquire the mutex before accessing, ensuring mutual exclusion. Note that this serializes all operations, limiting throughput.

3. Identify limitations of mutex

Explain that with a mutex, even multiple subscribers (readers) cannot access concurrently, leading to unnecessary blocking and reduced throughput, especially in read-heavy scenarios.

4. Introduce read/write lock

Propose a read/write lock: subscribers acquire a shared (read) lock, allowing multiple concurrent reads; publishers acquire an exclusive (write) lock, blocking all others. This increases parallelism for reads while maintaining data consistency.

5. Discuss trade-offs and alternatives

Mention that read/write locks have overhead and can lead to writer starvation. Suggest alternatives like fair locks, RCU, or lock-free data structures for specific scenarios. Conclude with a recommendation based on the read/write ratio.

Key Points to Mention

  • Mutex ensures mutual exclusion but serializes all access, limiting concurrency.
  • Read/write lock allows multiple concurrent readers (subscribers) but exclusive writers (publishers).
  • Throughput improvement depends on read/write ratio; read-heavy workloads benefit most.
  • Potential issues: writer starvation, increased overhead, and complexity.
  • Alternatives: fair read/write locks, RCU, lock-free queues, or partitioning.
  • Consider the granularity of locking (e.g., per-topic locks) to further improve concurrency.

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