DEV Community

Aditya Pandey
Aditya Pandey

Posted on

🐦 **How Would You Design Twitter?** (Plus: Threads vs Processes, Choosing Databases, and Unique ID Generation)

In this deep-dive post, we explore system design insights, foundational CS concepts, and architecture patterns from real-world use cases. Let’s unpack πŸ‘‡


Image description

πŸ’‘ Interview Essential: Process vs Thread

Understanding the difference between processes and threads is a must-have for any backend or systems engineer.

πŸ”Ή A Program is just a passive set of instructions on disk.

πŸ”Ή A Process is a program in action β€” it’s loaded into memory, with its own resources (stack, registers, etc.)

πŸ”Ή A Thread is the smallest unit of execution, running within a process β€” multiple threads can share memory and resources.

Key differences:

πŸ”Ή Processes are isolated; threads run within the same memory space.
πŸ”Ή Context switching is heavier for processes than threads.
πŸ”Ή Threads allow faster communication but require careful synchronization.
πŸ”Ή Creating processes is resource-intensive; threads are lightweight.

πŸ’¬ Over to you:
1️⃣ How do coroutines differ from threads in languages like Go or Python?
2️⃣ How would you list all running processes in Linux?


Image description

πŸ› οΈ System Design Interview: Design Twitter

Based on a 2013 Twitter tech talk, here’s how a tweet travels through Twitter’s architecture:

The Life of a Tweet
1️⃣ Tweet comes in via the Write API
2️⃣ Routed to the Fanout service
3️⃣ Stored and processed in Redis cache
4️⃣ Timeline service locates the relevant Redis shard
5️⃣ User pulls the timeline via the Timeline service

Search & Discovery

πŸ”Ή Ingester: Tokenizes tweets for indexing
πŸ”Ή Earlybird: Stores the searchable index
πŸ”Ή Blender: Builds search and discovery timelines

Push Compute

πŸ”Ή HTTP Push
πŸ”Ή Mobile Push

πŸ” Note: Based on Twitter’s 2013 architecture β€” still valuable for understanding scalable social media backends. Original Talk

πŸ’¬ What are the architecture differences between LinkedIn and Twitter? How do their use cases influence design?


Image description

🧩 Choosing the Right Database – A Visual Guide

Databases are not one-size-fits-all. Always choose the right DB for the workload:

Common types:

πŸ”Ή Relational (SQL) – Great for structured data and ACID compliance
πŸ”Ή Key-Value / In-Memory – Speed first (e.g., Redis)
πŸ”Ή Time Series – Optimized for time-stamped data
πŸ”Ή Document / JSON – Flexible schema (e.g., MongoDB)
πŸ”Ή Graph – Best for relationships (e.g., Neo4j)
πŸ”Ή Blob / Text Search / Geospatial / Ledger – Specialized needs

πŸ’¬ Which databases have you used? How did they perform for your workload?

Thanks to Satish Chandra Gupta for the visual inspiration!


Image description

πŸ” Unique ID Generator – A Must for Scalable Systems

Large-scale systems like Facebook, Twitter, and LinkedIn need unique IDs that meet tough requirements:

πŸ”Ή Globally unique
πŸ”Ή Roughly time-sorted
πŸ”Ή Numeric-only
πŸ”Ή 64-bit
πŸ”Ή Low-latency & scalable

Think of this as the backbone of tweet IDs, post IDs, user IDs. The implementation details vary, but the goal remains the same β€” fast, distributed, and conflict-free identity.

πŸ’¬ What kind of ID generation strategies have you used (UUIDs, Snowflake, etc.)?


Let’s keep learning from real-world architectures and build scalable, resilient systems together!

Top comments (0)