Key-Value and Graph Models
Two models at opposite ends: one that does almost nothing very fast, and one built entirely around following relationships.
Key-Value and Graph Models
Both models, and the SQL equivalents
Two models at opposite ends: one that does almost nothing very fast, and one built entirely around following relationships.
Both models, and the SQL equivalents
A key-value store maps a unique key to a value. The central operation is usually retrieving, creating, or updating that value by key. This simple model can fit sessions, caches, counters, and state whose access patterns are known in advance. The value may be opaque to the store, limiting queries across its internal fields.
A key-value store maps a unique key to a value. The central operation is usually retrieving, creating, or updating that value by key. This simple model can fit sessions, caches, counters, and state whose access patterns are known in advance. The value may be opaque to the store, limiting queries across its internal fields.
Redis is a common example and supports several richer data types beyond a plain string. Its data structures and persistence options mean it is not merely a simple dictionary; choose the operation and durability behavior deliberately.
A graph database represents entities as nodes and their relationships as edges, often with properties on both. It is useful when a question requires traversing several connections, such as paths between people, dependencies, or recommendations. The relationship itself is a first-class part of the model.
A relational database can represent the same graph with tables and joins. A graph engine may make repeated, variable-depth traversal easier, but does not make every query faster. If most requests are simple lookups by ID, a graph model may add complexity without helping.
Ask what the application needs to query and update, how relationships change, and what consistency and transaction guarantees are required. Do not choose a database because a category sounds newer. You may also combine stores, but then decide which system owns each fact and how updates remain consistent.
For comparisons with document databases and relational tables, see relational databases and non-relational databases.
A session store keyed by a random session token may need only set, get, expiry, and delete operations; a key-value model maps directly to that workload. A dependency explorer may need to walk from one service through several dependency levels; a graph model makes those edges central. If requirements later include rich filtering over arbitrary fields, the original simple model may need indexes, a different store, or a second representation. Capture expected queries and update rules before selecting the model.
A cache that can be rebuilt has different persistence needs from a store holding the only copy of a customer's state. Check whether the selected key-value product persists data, how replication and failover work, and what commands are atomic. For graph queries, define maximum traversal depth, path semantics, and cycle behavior. These concerns are part of choosing a data model, not details to leave until deployment. Prototype the hardest expected query and update before committing to the model.
Answer without scrolling back up.
Why is a key-value store fast?
The narrow interface is the feature. The cost is that every access path must be designed in advance and encoded in the key.
How does a graph edge differ from a SQL foreign key?
This is why traversal cost scales with edges visited rather than table size, and why the gap against joins widens with depth.
What is a graph database usually worse at than a relational one?
The test for reaching for a graph model is whether your interesting questions are about connections rather than about attributes.
Compare key-value and graph models against relational tables, see the queries each answers in one hop, and learn when leaving SQL pays off.