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)