SQL or NoSQL: which one fits a photo app?
FotoFlow has 10,000 users and the data model is settling, so the database choice made now will be hard to undo. Most apps start with a relational database such as PostgreSQL or MySQL: data in tables with a fixed set of columns, a schema, tables pointing at each other with keys, and a join combining them in one query. When unsure, relational databases are a very safe default.
The relational guarantee
Moving 50 dollars from Ana to Ben is two updates, and a crash between them makes money disappear. A transaction groups them: both happen or neither does, the ACID guarantee. That is why payments, orders, and likes counts live relational.
The classic pain points show up later. A products table sprouts hundreds of mostly-empty columns because shoes have sizes and laptops have CPUs, and every new product type means a migration on a huge table, some of which lock it for hours. And all writes still go through one database server.
Documents, keys, and what you give up
A document store such as MongoDB keeps each record as a self-contained document: a shoe and a laptop with completely different fields, no migration to run, reading one product as a single fetch, spreading naturally across servers. Documents shine when you read and write whole objects at once: catalogs, profiles, content.
A key-value store such as Redis or DynamoDB is the simplest of all: get and set by key, in about a millisecond. Perfect for sessions, carts, and counters, anything you always fetch by one id.
The trade: NoSQL stores scale out easily largely *because* they give things up, joins across records, multi-record transactions, and often strict consistency. Picking NoSQL for scale you do not have yet often means rebuilding joins and transactions by hand. The lines blur, PostgreSQL stores JSON, MongoDB offers transactions, but the defaults still lean these ways.
Pick per kind of data
Real systems mix stores, called polyglot persistence. For FotoFlow: money and orders stay relational for transactions, photo metadata and profiles could live in documents if shapes diverge, sessions already go to a key-value store. Start with one database and add another only when a kind of data clearly wants it. The question is not SQL or NoSQL, but what this data needs: relations, flexibility, or raw lookup speed.
One specialist worth knowing: free-text search. Typing "red sunset" into a search box becomes WHERE caption LIKE '%red%' on millions of rows, slow and unable to rank or handle typos. A search engine builds an inverted index, for every word the list of documents containing it, fed from the main database by a stream of changes. It is a copy, not the source of truth, and can always be rebuilt.
What this does not solve
Choosing the store says nothing about how fast it answers. A perfectly chosen SQL database can still take two seconds to find one user by email, and the fix is not a bigger database. That is the next post.
If you renamed a column tomorrow, which of your app's features would notice first?
Which table in your schema is already sprouting mostly-empty columns, and what is it secretly trying to become?
One database, chosen per question the data must answer.
Next in the series: One table got slow: do you need a bigger database yet?
Sources
Designing Data-Intensive Applications
Amazon Dynamo (2007)
undefined
System Design Primer
Recommended for you
- Craft & Skills
One server, 10 million users: how does a photo app survive that?
A 40-post series that follows FotoFlow, a photo app, from one server and 100 users to 10 million users with direct messages. One problem, one fix, one honest cost at a time.
- Craft & Skills
Ten million users want direct messages: could you design the chat system?
The final design: 20 million open sockets and a promise that every message arrives, in order, exactly once. Dumb gateways, a connection registry, store-first durability and sync by cursor.
- Craft & Skills
Five million home feeds: how do you build the page everyone opens?
The home feed must load in 200 ms from two hundred followed accounts. Fan-out on read melts at 4.6 million lookups a second; fan-out on write melts on celebrities; the hybrid survives both.
- Craft & Skills
FotoFlow wants short share links: could you design one today?
The first full design walkthrough: turn a one-line brief into numbers, the simplest system, then fix codes, caching, storage and abuse one bottleneck at a time. The method is the point.
Enjoyed this article?
Subscribe for new articles. No spam. Unsubscribe anytime.
Typed live, never pasted.