๐Ÿ“˜ How is a DBMS Implemented?

This is a deep systems-level question that FAANG and equivalent companies love โ€” because it tests how well you understand whatโ€™s under the hood of a DBMS, not just how to use it.


๐Ÿ’ก TL;DR:

A DBMS is a complex software system implemented using a mix of:

  • File systems

  • Data structures

  • Memory management

  • Algorithms

  • Concurrency control

  • Storage engines

Letโ€™s break it down into layers โ€” like an operating system or compiler.


๐Ÿงฑ 1. Storage Manager (Lowest Layer)

๐Ÿ” What it does:

  • Manages how data is stored on disk

  • Handles files, pages, and blocks

  • Controls buffer management and disk I/O

๐Ÿ”ง Includes:

  • Data files โ€“ raw storage of tables and indexes

  • System catalog โ€“ stores metadata like schemas, constraints

  • Buffer manager โ€“ moves data between RAM and disk

  • File manager โ€“ reads/writes blocks of disk


๐Ÿง  2. Query Processor

This is the brain of the DBMS that understands SQL and turns it into actual data operations.

๐Ÿ” What it does:

  • Parses SQL queries

  • Optimizes the query plan

  • Executes the optimized plan

๐Ÿ”ง Includes:

  • Parser โ€“ checks syntax and builds a query tree

  • Optimizer โ€“ chooses the best plan (e.g., use index vs full scan)

  • Executor โ€“ actually runs the query plan step-by-step


๐Ÿ”’ 3. Transaction Manager

Handles ACID properties (Atomicity, Consistency, Isolation, Durability).

๐Ÿ” What it does:

  • Starts and ends transactions

  • Maintains logs for recovery

  • Manages locks to handle concurrent users

๐Ÿ”ง Includes:

  • Concurrency control (2PL, MVCC, etc.)

  • Logging system (Write-Ahead Log - WAL)

  • Deadlock detection


๐Ÿ›ก๏ธ 4. Authorization & Security Manager

Controls:

  • Who can do what (e.g., SELECT, INSERT)

  • What views and roles exist

  • Data privacy


๐Ÿงช Real DBMS Stack:

Letโ€™s take PostgreSQL as an example.

LayerTech/Component
Disk I/OOS + file system
Storage EnginePostgreSQL heap files
Buffer ManagerShared memory buffers, LRU cache
Query ProcessorSQL parser + planner + executor
Transaction ManagerMVCC + WAL logs
ConcurrencyLock manager
APIsSQL, C-language functions, PL/pgSQL

๐Ÿง  Interview Line:

โ€œA DBMS is implemented in layered architecture โ€” with a storage manager handling data blocks, a query processor parsing and optimizing SQL, a transaction manager enforcing ACID, and security layers ensuring controlled access.โ€


๐Ÿง  Bonus for FAANG Interviews:

If asked how you would design a DBMS, mention:

  • Storage with B+ Trees or LSM Trees

  • Query parsing with abstract syntax trees (AST)

  • Optimizer with cost-based planning

  • MVCC for isolation

  • WAL for durability

  • Background processes for vacuuming/compaction