Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Foundations of Scale
Lesson 10 of 16

SQL and NoSQL basics

Choose a data store by its access patterns and guarantees, not by fashion.

16 min read

Relational 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.

Cache invalidation and write patternsIndexes and query performance

Coming up

Course: 0/16 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 5/10Design a Blogging PlatformModel posts and comments in SQL with the right indexes, then cache and CDN the read path.Easy
  2. 6/10Design a File Upload ServiceAccept large uploads with presigned URLs to object storage, metadata in SQL and a scanning worker.
Easy
All 10 challenges →