Indexing & Replication

Lesson · Junior

Faster reads and surviving failures.

Indexes

An index (often a B-tree) lets the database find rows without scanning the whole table. Reads get much faster; writes and storage cost more because the index must be updated. Index columns you filter and sort on, not everything.

Replication

Copy data to several nodes. Leader–follower: writes go to the leader, reads can be served by followers, and a follower is promoted if the leader fails. Gives read scaling and fault tolerance.

Replication lag

Asynchronous replication means followers may be slightly stale, so a user might not see their own write immediately. Mitigate by reading your own writes from the leader.