SQL and NoSQL basics
Choose a data store by its access patterns and guarantees, not by fashion.
16 min readRelational databases
A relational (SQL) database stores data in tables with a fixed schema and relationships expressed through keys. Its strengths are flexible queries, joins, constraints such as unique and foreign keys, and ACID transactions: a group of changes either all happens or none does, even under concurrency. That makes SQL the default for anything involving money, inventory, accounts or relationships between entities. A single well-tuned primary on modern hardware handles thousands to tens of thousands of simple queries per second and terabytes of data, which covers far more systems than people expect.
NoSQL families
NoSQL is an umbrella for stores that give up some relational features in exchange for scale, speed or a better fit for one access pattern.
- Key-value (Redis, DynamoDB): get and put by key, very fast, little querying
- Document (MongoDB): nested JSON-like records, flexible schema, good for self-contained objects
- Wide-column (Cassandra): partitioned rows, very high write throughput, queries designed around the partition key
- Graph (Neo4j): relationships as first-class data, good for traversals such as friends of friends
Choose by access pattern
Start from the queries the system must answer, not from the store. If you need ad hoc filters, joins and transactions, use SQL. If almost every read is a lookup by a single key, such as a short code to a URL or a session ID to a session, a key-value store is simpler and scales horizontally with little effort. If you write hundreds of thousands of events per second and read them by time range per device, a wide-column store fits. Many real systems combine several: SQL as the source of truth, a cache for hot reads and a search index for text queries.
Consistency trade-offs
Distributed NoSQL stores often replicate asynchronously and offer eventual consistency by default: a read right after a write may return the old value for a short time. Some let you choose per request, trading latency for a stronger guarantee. For a like counter, eventual consistency is fine; for a username uniqueness check or a balance, it is not. When you place a database on the SystCode canvas, the component choice should follow from these requirements, and your design notes should say why.
Key takeaways
- SQL gives flexible queries, constraints and transactions, and scales further than most people think
- NoSQL stores trade query flexibility for scale or a better fit to one access pattern
- List your queries first, then pick the store that answers them cheaply
- Know whether each piece of data can tolerate eventual consistency
Sign in to track lessons and earn badges.