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.
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.
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)?
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.