Skip to content
StackDecode
System Design
4. Database FundamentalsAnimated

Indexing

A structure that finds rows quickly without scanning the whole table.

The idea

An index maps column values to row locations, like a book index. Reads speed up while writes cost a little more.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

App serversPrimary (writes)Replica 1 (read…Replica 2 (read…
  • client
  • gateway / proxy
  • service
  • cache
  • data store
  • queue / stream

Step one: add indexes and cache.

step:
1/4
at:
App servers
1/7

The green dot is a request moving through the system.

Step by step

  1. 1Choose columns used in filters and joins
  2. 2Create the index
  3. 3The planner uses it to jump to rows
  4. 4Maintain it on every write

Where it is used

Any query on large tables.

Watch out for

Too many indexes slow writes and use space.

Related