Skip to the page

Data and messaging · 24 concepts

Databases in depth

Beyond SQL queries: how PostgreSQL and MySQL work inside, MongoDB and NoSQL, Redis caching, and how to scale and change a database safely.

Part 1 · 5 concepts

PostgreSQL and MySQL inside

  1. 01

    MVCC: how PostgreSQL lets readers and writers work together

    PostgreSQL never changes a row in place. An UPDATE writes a new row version, and each query uses a snapshot to decide which versions it can see, so readers and writers…

  2. 02

    VACUUM, bloat and transaction id wraparound

    Dead row versions must be cleaned by VACUUM. When something blocks the cleaning, tables bloat and slow down, and in the worst case PostgreSQL runs out of transaction…

  3. 03

    InnoDB inside: clustered index, undo log and gap locks

    InnoDB stores a table as a B+ tree on the primary key, keeps old versions in an undo log and, at its default isolation level, locks gaps between index records. These…

  4. 04

    Replication and read-after-write problems

    A replica applies changes a little after the primary commits them. A read right after a write can hit the replica too early and show old data. You must know how to…

  5. 05

    PostgreSQL or MySQL: how to choose

    Both are mature and good for most transactional work. A senior answer names real differences and costs, and also says that team skills and the managed service often…

Part 2 · 7 concepts

NoSQL and MongoDB

  1. 06

    SQL or NoSQL: the families and how to choose

    NoSQL is not one thing. Each family fits a data shape and an access pattern. You choose by shape, queries, consistency and what the team can run, not because someone…

  2. 07

    Flexible attributes: JSONB, columns, EAV or documents

    A catalog where each category has different attributes can use JSONB, a wide table, an attribute-value table, or a document database. A hybrid is often best.

  3. 08

    MongoDB data modelling: embed or reference

    In MongoDB you model from the screens and queries. Data read together is stored together. What grows without limit goes in its own collection.

  4. 09

    MongoDB indexes, the ESR rule and explain

    A compound index works best when its fields are ordered Equality, then Sort, then Range. You check it with explain and by looking at keys examined against documents…

  5. 10

    The aggregation pipeline

    An aggregation pipeline is a list of stages. Put $match and $limit early, so fewer documents travel through the later stages.

  6. 11

    MongoDB write concern, failover and transactions

    With a weak write concern, a primary can confirm a write that a failover then loses. MongoDB also has multi-document transactions, but good modelling needs them less…

  7. 12

    Key design in DynamoDB and Cassandra

    These stores can answer only the queries their keys support. You start from the access patterns and choose partition and sort keys, then handle hot partitions.

Part 3 · 6 concepts

Redis and caching

  1. 13

    Redis data structures for real features

    Redis is more than a cache. Choose the structure that matches the feature: sorted sets, hashes, HyperLogLog, lists and streams. Each command runs atomically.

  2. 14

    Cache-aside, invalidation and stale prices

    In cache-aside, the app reads the cache first and fills it from the database on a miss. The hard part is invalidation: after a write, delete the key, and plan for every…

  3. 15

    Cache stampede and hot keys

    When a hot key expires, every request misses at once and all of them run the expensive query. You need one rebuilder, a stale fallback and spread-out expiry.

  4. 16

    Redis memory, eviction and slow commands

    Redis keeps data in memory and runs commands one at a time. You must know what happens at maxmemory and which commands block everyone.

  5. 17

    Distributed locks with Redis

    A Redis lock is useful to avoid duplicate work, but it cannot guarantee safety alone. For money, the database must enforce uniqueness.

  6. 18

    Redis or Valkey: licence and choice

    Redis changed its licence in 2024 and Valkey was started as a fork. Core commands work on both. A good answer names the licence facts and says to test before switching.

Part 4 · 6 concepts

Scaling and changing databases

  1. 19

    Connection pooling and 'too many clients'

    Each database connection costs memory. When many pods each hold a big pool, the total passes max_connections. A pooler such as PgBouncer shares a few server connections…

  2. 20

    Scaling a busy database step by step

    Before a big traffic event, measure first, then use the safest fixes first: queries, cache, pooling, read replicas, a bigger machine. Partitioning and sharding come last.

  3. 21

    Partitioning or sharding

    Partitioning splits one table inside one server. Sharding splits data across several servers. They solve different problems.

  4. 22

    Shard keys, hot shards and unique ids

    A shard key decides where data lives. A good key spreads load evenly and keeps common queries on one shard. A bad key makes one hot shard. Ids must be unique across…

  5. 23

    Changing a live database without downtime

    Schema changes, version upgrades and data moves must be planned in small, reversible steps, with timeouts and a way back.

  6. 24

    Backups, point-in-time recovery and DELETE without WHERE

    A backup is only real when you have tested a restore. After a wrong DELETE, the goal is to recover the lost rows without losing the new data written since.

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview