GET and PUT Operations
You'll learn: the two fundamental operations used to retrieve and store data in key-value stores, and why they're so fast.
The Core Idea
In key-value stores, GET and PUT are the primary operations for interacting with your data. Think of a key-value store like a massive digital locker room: PUT stores an item in a specific locker (identified by a key), and GET retrieves whatever's in that locker. These operations are designed to be extremely simple and lightning-fast.
GET Operation
GET retrieves the value associated with a specific key. Because key-value stores use hash-based key distribution (as you just learned), the database can calculate exactly where the data lives and fetch it directly—no searching required.
Performance: Typically O(1) constant time. The hash function instantly maps your key to a storage location.
PUT Operation
PUT stores or updates a value for a given key. If the key doesn't exist, it creates a new entry. If it does exist, it overwrites the old value.
Performance: Also typically O(1) constant time. The same hash function determines where to write the data.
Why They're So Fast
Unlike relational databases that might need to traverse B-trees, check constraints, or update multiple indexes, key-value operations are direct memory or disk lookups. The hash-based distribution eliminates search time—you compute the location, then go straight there.
This simplicity is both the strength and limitation: you get incredible speed for direct lookups, but you can't easily query by value, perform range scans, or join data across keys.
Key Takeaway: GET and PUT operations provide O(1) constant-time retrieval and storage in key-value stores by leveraging hash-based key distribution for direct data access.