Skip to main content

System Design Speed Tricks - How Things Work So Fast

Learn the algorithms, data structures, and infrastructure patterns that make modern systems respond in milliseconds. From client-side validation to global routing, understand why things feel instant.

intermediate
System Design

System Design Speed Tricks - How Things Work So Fast

Learn the algorithms, data structures, and infrastructure patterns that make modern systems respond in milliseconds. From client-side validation to global routing, understand why things feel instant.

14 cards
25 minutes
1 / 14
0% Known
0
? 0
Card 1 of 14
Fundamentals
Swipe left/right to navigate cards
Question

You need to check if a user ID exists in a set of 10 million active sessions. A list scan takes seconds, but a different approach answers in microseconds. What is the difference between O(1) and O(n) lookups, and which data structure gives you O(1)?

Tap to reveal
Answer

O(n) means you potentially scan every element (a list). O(1) means constant-time access regardless of size. A **hash table** (hash map, dictionary, set) gives O(1) average lookup by computing an index from the key: ```python # O(n) - scanning a list user_ids = [1, 2, 3, ..., 10_000_000] if target in user_ids: # checks up to 10M items # O(1) - hash set user_ids = {1, 2, 3, ..., 10_000_000} if target in user_ids: # one hash computation ``` This single distinction underpins nearly every speed trick in system design.

time-complexity
hash-tables
lookups