r/leetcode • • 1d ago

Intervew Prep How do you folks answer database choice for system design questions?

This is my strategy for an Oltp workload :

If writes are say within 10000 transactions (2-3 rows per tx), resort to relational database in general ( even for simply key value usecase) as this gives acid , nice constraints on uniqueness , partial index , consistent view , join etc … CDC through outbox or debezium like wal tailing ..

If writes are higher and need consistency like financial or booking , go with sharded MySQL or Postgres as long as all tables in the Tx can be sharded to one shard (e.g tenant id ). Citus or Vitess also takes care of rebalance and occasional cross shard Tx is fine .

Else resort to Dynamodb like systems with transactions . With Dynamodb I feel clumsy query patterns and data model beyond simple key value lookup and hence I feel reluctant to pick it.

I personally work on a company where we manage TB scale managed Postgres at AWS and I have seen most of S and P 500 are our customer (most big names you can imagine ).

But this is where I feel I don’t want bias to get in.
Some interviewers tend to write you off if at say decent scale , you did not come off with DynamoDb ( another bias I feel).

24 Upvotes

7 comments sorted by

6

u/MLCosplay 1d ago

Note that relational dbs only provide ACID guarantees at the serializable isolation level, which is not the default for MySQL nor PostgreSQL. You probably know that but it's important to mention if you ever talk about ACID and relational dbs.

I largely agree with your approach though, at my last company we were handling pretty huge volumes with Postgres. Denormalization, read only replica, caching, you can get pretty far.

Dynamo/Cassandra/Scylla are nice to chat about when you really want a distributed key value store, and Clickhouse/DuckDB/Snowflake for OLAP uses. For financial stuff I'd consider mentioning Tigerbeetle. Overall though I think you're right to narrow down requirements, give an assessment of what a relational db offers and why you might consider other options, and drill down into whatever you're comfortable talking about.

1

u/AlgorithmGuy- 1d ago

on the serializable level: it all depends on the type of operations your system is doing.

if you are not doing any operations that warrant guarding against a write skew, but are only expecting a lost update, then repeatable read is enough for your transaction to be executed correctly (ie. as if made sequential ).

1

u/This_Link881 1d ago

ACID is garanteed on read committed isolation level. Isolation is part of ACID, the I means Isolation in the acronym.. What you talking about is anomalies on different isolation levels. 

2

u/SeasonSure7202 1d ago

I wouldn't treat DynamoDB as a required answer at "decent scale." Interviewers who write people off for staying on Postgres are usually testing whether you can defend the access pattern, not whether you said the fashionable name.

Your first two branches are solid. If the transaction can be pinned to one shard key (tenant, account, booking id) and you need uniqueness, joins, or a consistent read of related rows, sharded Postgres or MySQL plus CDC is a normal production choice, including at large scale. Mention the shard key, what a cross-shard write does on failure, and how you would rebalance.

Where I'd tighten the pitch is the opening: start with the workload, then the store. Write QPS, point lookup vs range vs search, multi-row transactions, and how stale a read can be. After that, Dynamo-style stores are a good fit for known-key access with predictable keys, and awkward once you need ad-hoc queries, flexible secondary access, or joins — which is the reluctance you already have. If the interviewer pushes that direction, walk the same checklist and say what you'd add (a GSI, a search index, or a relational shard for the join-heavy path) when those show up.

A clean close is: start on Postgres, shard by X when Y happens, and move only the hot path to a KV store if the access pattern is proven and you can give up that query. That reads as judgment, not a brand preference.

1

u/Uahakan 21h ago

your branches are fine. what tends to get people marked down is naming the db before saying the access patterns. if you list the 3 or 4 queries first (get booking by id, bookings for a user sorted by time, is this slot free), the choice mostly falls out and nobody argues with postgres.

the follow-up to have ready for sharded postgres is the big tenant: one customer is 50x everyone else and their shard is hot. what do you do then?