- Chapter
- Chapter 1 — Database Fundamentals
- Prerequisites
- Topic 1.1
- You will be able to
- Describe what a DBMS is and its internal layers, distinguish RDBMS from other database kinds, explain the role of the database server and of storage engines, compare popular RDBMS products for Java systems, and choose a DBMS based on workload and operational requirements
- Covers
- DBMS; RDBMS; Database server; Storage engine
On this page
- 1. Concept / Definition
- 2. Why It Exists
- 3. Core Concepts
- 4. How It Works Internally — The Layers at Work
- 4A. Deep Dive — Choosing a DBMS
- 5. APIs / Features / Syntax
- 6. Practical Examples
- 7. Common Problems & Mistakes
- 8. Performance & Production Considerations
- 9. Architecture & Design Considerations
- 10. Interview Questions & Answers
1Concept / Definition
A Database Management System (DBMS) is the software that defines, stores, retrieves, protects and manages databases on behalf of applications and users. A Relational DBMS (RDBMS) is a DBMS based on the relational model: data in tables, manipulated through SQL, with integrity constraints and ACID transactions.

| Term | Meaning | Example |
|---|---|---|
| Database | The organised data itself | shop database |
| DBMS | Software managing databases | PostgreSQL, MongoDB |
| RDBMS | Relational DBMS | PostgreSQL, MySQL, Oracle, SQL Server |
| Database server | Running DBMS instance accepting connections | postgres process on port 5432 |
| Storage engine | Component that physically stores and retrieves data | InnoDB, PostgreSQL heap access method |
| Instance / cluster | One server installation hosting several databases | PostgreSQL "cluster" = data directory |
2Why It Exists
Every application needs the same hard capabilities: storage layout, indexing, query evaluation, concurrency control, recovery, security and backup. Building these per application is prohibitively expensive and error-prone. The DBMS factors them out into general-purpose, heavily optimised software. ANSI/SPARC's three-level architecture (1975) formalised the separation between external views, the logical schema and physical storage — the basis of data independence.
3Core Concepts
3.1 DBMS
| DBMS function | Examples |
|---|---|
| Data definition | CREATE TABLE, types, constraints, schemas |
| Data manipulation | SELECT, INSERT, UPDATE, DELETE |
| Query optimisation | Cost-based planning, index selection |
| Transaction management | Atomicity, isolation, locking/MVCC |
| Recovery | WAL, checkpoints, crash recovery, PITR |
| Security | Authentication, roles, privileges, row-level security, encryption |
| Administration | Statistics, vacuum, backup, replication, monitoring |

3.2 RDBMS
An RDBMS implements Codd's relational model (with SQL's pragmatic extensions):
| Relational property | Practical meaning |
|---|---|
| Data in relations (tables) | Uniform representation |
| Declarative query language (SQL) | Say what, not how |
| Integrity constraints | Keys, foreign keys, checks enforced by the system |
| ACID transactions | Reliable multi-statement changes |
| Data independence | Indexes/storage change without query changes |
| Set-based operations | Joins, aggregates over sets of rows |
Beyond pure relational: modern RDBMSs support JSON (jsonb), full-text search, arrays, geospatial data (PostGIS), window functions and extensions — blurring lines with document and analytical stores while keeping ACID.
3.3 Database server
The database server is the running DBMS process (or set of processes) that listens for connections, authenticates clients, executes SQL and manages memory, files and background work.
| Server responsibility | Example (PostgreSQL) |
|---|---|
| Accept connections | postmaster listens on 5432; pg_hba.conf authentication |
| Manage sessions | One backend process per connection |
| Shared memory | Shared buffers, WAL buffers, lock tables |
| Background work | Checkpointer, WAL writer, autovacuum, replication senders |
| Configuration | postgresql.conf (memory, WAL, connections) |
Deployment forms: self-managed on VMs, containers/Kubernetes operators (CloudNativePG), or managed cloud services (Amazon RDS/Aurora, Google Cloud SQL/AlloyDB, Azure Database) that handle backups, patching and failover.
3.4 Storage engine

The storage engine determines how rows and indexes are laid out and how reads/writes behave.
| Storage design | Example | Strength | Weakness |
|---|---|---|---|
| Heap + separate B-tree indexes | PostgreSQL | Flexible, many index types | Index lookups need heap fetch (unless index-only scan) |
| Clustered B-tree (table = PK index) | InnoDB, SQL Server clustered index | Fast PK range scans | Random PKs (UUIDv4) fragment pages |
| LSM tree | MyRocks, RocksDB, Cassandra | High write throughput, compression | Read amplification, compaction |
| Columnar | ClickHouse, Citus columnar, Oracle In-Memory | Analytics, compression | Slow single-row updates |
Why a Java architect cares: choice of primary key type (identity vs UUIDv4 vs UUIDv7) interacts with the engine — random UUIDv4 PKs cause page splits in clustered engines and index bloat everywhere; time-ordered UUIDv7 behaves much better.
4How It Works Internally — The Layers at Work
| Step | Layer | What happens for SELECT * FROM customer WHERE email = ? |
|---|---|---|
| 1 | Interface | Driver sends query over wire protocol; session authenticated |
| 2 | Query processor | Parse, analyse (resolve table/columns), plan: choose index scan on email unique index |
| 3 | Transaction manager | Take snapshot for MVCC visibility |
| 4 | Storage engine | Traverse B-tree, fetch heap page from buffer pool (or disk), check visibility |
| 5 | Interface | Serialise row back to client |
4ADeep Dive — Choosing a DBMS

| Decision factor | Questions |
|---|---|
| Data model fit | Relational with integrity needs? Documents? Graph traversal? Time-series? |
| Transactions | Multi-row ACID needed? Cross-entity invariants? |
| Scale profile | Data size, write rate, read rate, growth; single-node vs distributed |
| Query needs | Ad-hoc SQL, reporting, full-text, geospatial, JSON |
| Operations | Team skills, managed service availability, backup/HA tooling |
| Ecosystem | JDBC/Hibernate dialect maturity, Flyway support, Testcontainers images |
| Cost & licensing | Open source vs commercial; cloud pricing |
Pragmatic default for Java business systems: PostgreSQL (or a managed variant) unless a specific requirement demands otherwise — polyglot persistence adds operational cost and should be justified per workload (e.g. Redis for caching, OpenSearch for search, ClickHouse for analytics).
5APIs / Features / Syntax
-- Inspect the server and storage
SELECT version();
SHOW shared_buffers;
SELECT relname, pg_size_pretty(pg_total_relation_size(oid))
FROM pg_class WHERE relkind = 'r' ORDER BY pg_total_relation_size(oid) DESC LIMIT 5;
-- MySQL: choose storage engine explicitly
CREATE TABLE audit_log (id BIGINT PRIMARY KEY, payload JSON) ENGINE = InnoDB;# Spring Boot 4 datasource (auto-configures HikariCP + dialect detection)
spring:
datasource:
url: jdbc:postgresql://db.internal:5432/shop
username: shop_app
password: ${DB_PASSWORD}
jpa:
open-in-view: false
hibernate.ddl-auto: validate # schema owned by migrations, not Hibernate| Java touchpoint | DBMS concept |
|---|---|
JDBC driver (org.postgresql:postgresql) | Wire protocol to server |
| Hibernate dialect | SQL generation per DBMS |
DatabaseMetaData | Server capabilities |
| Testcontainers module per DBMS | Real server in tests |
6Practical Examples
6.1 Unnecessary polyglot persistence
A team used MongoDB for orders "for flexibility" and PostgreSQL for payments, then needed cross-store consistency and joins for reports. Consolidating orders into PostgreSQL with a jsonb column for the flexible part removed a whole integration layer.
6.2 Engine-aware key choice
A MySQL/InnoDB table keyed by random UUIDv4 suffered page splits and 3× index size. Switching new rows to UUIDv7 (time-ordered) restored insert throughput.
6.3 Worked example — DBMS selection for three workloads
| Workload | Requirements | Choice | Reason |
|---|---|---|---|
| Order management | ACID, FKs, reporting joins, moderate scale | PostgreSQL (managed) | Relational integrity, rich SQL |
| Product search | Full-text, facets, typo tolerance | OpenSearch (fed by events) | Search engine features |
| Click analytics (billions of events) | Append-only, aggregations | ClickHouse | Columnar compression and speed |
6.4 Worked example — managed vs self-managed
| Concern | Managed (RDS/Cloud SQL) | Self-managed (VM/Kubernetes) |
|---|---|---|
| Backups, PITR | Built in | Build/operate (pgBackRest) |
| Failover | Automated Multi-AZ | Patroni/CloudNativePG setup |
| Extensions | Limited list | Any |
| Tuning access | Parameter groups | Full |
| Cost | Higher per GB, lower people cost | Lower infra, higher ops effort |
6.5 Worked example — identifying the storage consequences of a design
-- PostgreSQL: see how much space table and indexes use, and index-only scan potential
SELECT indexrelname, idx_scan, pg_size_pretty(pg_relation_size(indexrelid)) AS size
FROM pg_stat_user_indexes WHERE relname = 'purchase_order';
EXPLAIN (ANALYZE, BUFFERS)
SELECT order_id, status FROM purchase_order WHERE customer_id = 101;| Observation | Interpretation |
|---|---|
Index Scan using ix_order_customer | Engine uses B-tree then fetches heap pages |
Buffers: shared hit=12 | Pages served from buffer pool — no disk |
| Unused index with 0 scans and 2 GB | Candidate for removal (Chapter 5) |
6.6 Worked example — the same logical table on two storage engines
-- Same logical definition
CREATE TABLE event_log (
id UUID PRIMARY KEY,
tenant_id BIGINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL,
payload JSONB NOT NULL
);| Behaviour | PostgreSQL (heap + B-tree) | MySQL InnoDB (clustered PK) |
|---|---|---|
| Physical row order | Insertion order in heap pages | Ordered by primary key |
| Insert with random UUIDv4 PK | Heap append fast; PK index gets random inserts (bloat) | Rows inserted into random leaf pages — page splits, poor locality |
| Insert with UUIDv7 PK | Mostly append-only index | Mostly append-only clustered index |
| Range query by PK | Index scan + heap fetches | Sequential read of clustered leaves |
| Secondary index lookup | Index → heap tuple pointer | Secondary index → PK → clustered index (two lookups) |
| Old row versions (MVCC) | Stored in heap; vacuum removes | Stored in undo log; purge removes |
// Time-ordered UUIDv7 keys in Java
// (e.g. Hibernate 7 @UuidGenerator or the java-uuid-generator library)
@Entity
public class EventLog {
@Id
@UuidGenerator(style = UuidGenerator.Style.VERSION_7)
private UUID id;
…
}| Takeaway | Design rule |
|---|---|
| Key choice interacts with engine layout | Prefer identity or UUIDv7 over UUIDv4 for high-insert tables |
| Secondary index cost differs | In clustered engines keep PKs narrow (they're copied into every index) |
| Maintenance differs | Plan vacuum (PostgreSQL) vs purge/undo (InnoDB) monitoring |
7Common Problems & Mistakes
- Treating the DBMS as interchangeable — ignoring engine and SQL dialect differences.
- Polyglot persistence without need — more stores, more integration and ops.
- Letting Hibernate create the schema in production (
ddl-auto=update). - Ignoring storage implications of key types and data types.
- Choosing by popularity rather than workload and operations.
- No DBA/operations ownership for self-managed servers.
8Performance & Production Considerations
| Aspect | Note |
|---|---|
| Memory | Shared buffers + OS cache determine hit ratio |
| Storage | IOPS and latency (cloud volumes) bound write/commit speed |
| Maintenance | Vacuum (PostgreSQL), statistics, index maintenance |
| Upgrades | Major-version upgrades need planning (pg_upgrade, logical replication) |
| Observability | pg_stat_statements, slow query logs, wait events |
9Architecture & Design Considerations
- Default to a well-understood RDBMS for transactional business data.
- Add specialised stores per workload with clear data ownership and sync paths.
- Keep schema ownership in migrations, not the ORM.
- Consider managed services to reduce operational risk; know their limits.
10Interview Questions & Answers
What is a DBMS?
A DBMS is the software that defines, stores, retrieves, protects and manages databases on behalf of applications and users. Instead of every application implementing its own file formats, indexes, locking and crash recovery, the DBMS provides them once as a shared, heavily optimised service. It typically has an interface layer that accepts connections and SQL, a query processor that parses and plans statements, a transaction manager for concurrency and recovery, and a storage engine that manages pages on disk. The key benefit is data independence: applications say what data they want, and the DBMS decides how to store and fetch it, so storage can change without code changes.
What makes a DBMS relational?
A DBMS is relational when it implements Codd's relational model: all data is represented as relations, that is tables of rows and columns, and is queried declaratively, today through SQL. The system itself enforces integrity through primary keys, foreign keys, unique and check constraints, and it groups multi-statement changes into ACID transactions. It also provides data independence, so adding an index or changing the physical layout does not change any query. Set-based operations such as joins and aggregates work over whole sets of rows. Modern RDBMSs like PostgreSQL add JSON, arrays and full-text search, but those are extensions on top of the relational core, not replacements for it.
What is a storage engine?
The storage engine is the layer of the DBMS that physically stores rows and indexes and implements reads, writes, locking and recovery at page level. The query processor decides what to do; the engine decides how bytes are laid out and fetched. Designs differ a lot: PostgreSQL keeps rows in an unordered heap with separate B-tree indexes, InnoDB stores the table inside a clustered primary-key B-tree, LSM-tree engines such as RocksDB buffer writes and compact later, and columnar engines store each column separately for analytics. MySQL lets you pick the engine per table. The engine determines insert speed, range-scan cost, index size and maintenance work such as vacuum or compaction.
What is the difference between a database and a database server?
The database is the organised data itself: the tables, indexes, schemas and their files in a data directory. The database server is the running DBMS instance that manages that data, listens on a port such as 5432, authenticates clients, executes SQL and runs background work like checkpoints, WAL writing and autovacuum. One server instance usually hosts several databases; PostgreSQL calls the instance plus its data directory a cluster. The distinction matters operationally: connection limits, memory settings, replication and failover are properties of the server, while schemas, privileges and data ownership belong to each database. Several microservices can share one server while each owns a separate database or schema.
Why can random UUID primary keys hurt performance?
A random UUIDv4 sends each insert to an arbitrary leaf page of the primary-key B-tree, so instead of appending to the right-most page the database keeps touching cold pages all over the index. That causes page splits, half-empty pages, poor buffer-cache hit ratios and more WAL. In clustered engines like InnoDB it is worse, because the table itself is the primary-key index and the 16-byte key is copied into every secondary index. The fix is a time-ordered key: an identity or sequence BIGINT, or UUIDv7, which keeps global uniqueness but inserts in roughly increasing order. In Hibernate 7, @UuidGenerator with style VERSION_7 generates them.
Why set hibernate.ddl-auto=validate in production?
In production the schema should be changed only by versioned, reviewed migrations, using Flyway or Liquibase, so every environment reaches the same state through the same scripts and every change can be audited. With update, Hibernate guesses DDL from entity mappings at startup: it can add columns but never safely renames, drops or migrates data, it may create poorly typed columns or miss indexes, and two instances starting together can race each other. Validate makes Hibernate only check that the mappings match the existing schema and fail fast at startup if they don't. That catches a forgotten migration at deployment time instead of as a runtime SQL error in front of users.
How do you choose a DBMS for a new system?
I start from the workload, not the product. First the data model: is it relational with cross-entity invariants, or documents, graphs or time series? Then transactional needs, the scale profile in data size, read and write rates and growth, and query needs such as ad-hoc reporting, full-text, JSON or geospatial. Next comes operations: team skills, managed-service availability, backup, HA and upgrade tooling. Finally ecosystem and cost: driver and Hibernate dialect maturity, Testcontainers support and licensing. For most Java business systems the result is a managed PostgreSQL, with a specialised store added only when a specific workload proves it is needed.
When is polyglot persistence justified?
Polyglot persistence is justified when a specific workload has requirements the primary RDBMS cannot meet well at the needed scale or cost, such as typo-tolerant faceted search, aggregations over billions of events, or sub-millisecond caching. Then OpenSearch, ClickHouse or Redis earns its place. Vague flexibility is not a reason, because every extra store adds operations, security, monitoring and cross-store consistency problems. When I add one, I define a single system of record for each piece of data, feed the secondary store through events or CDC, accept eventual consistency explicitly, and make sure the store can be rebuilt from the source.
Test your knowledge on this topic →Flashcards from this topic's 8 questions, filtered by level and type.