๐ 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.
| Layer | Tech/Component |
|---|---|
| Disk I/O | OS + file system |
| Storage Engine | PostgreSQL heap files |
| Buffer Manager | Shared memory buffers, LRU cache |
| Query Processor | SQL parser + planner + executor |
| Transaction Manager | MVCC + WAL logs |
| Concurrency | Lock manager |
| APIs | SQL, 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