An embedded database is a database engine that runs as a library inside the application process rather than as a separate server, so the program reads and writes data through direct function calls instead of a network protocol. Among database models in Databases, it describes a deployment architecture rather than a data model: an embedded engine can be relational, key-value, document-oriented or even graph-based.
Typical examples include SQLite, Berkeley DB, RocksDB, LMDB and DuckDB. They power mobile apps, browsers, desktop software, network devices, IoT firmware and many server components that need durable local state with zero administration.
How an embedded database runs inside the application
An embedded database works by compiling or linking the storage engine, query layer and transaction manager into the host program, so every query executes in the same address space as the calling code. There is no listener socket, no authentication handshake and no separate daemon to start, monitor or upgrade.
Data usually lives in one file or a small directory on local storage. The engine manages durability through a write-ahead log or a rollback journal, uses file locks or memory-mapped pages to coordinate access, and recovers automatically after a crash by replaying or discarding incomplete transactions. Because calls avoid serialization and network round trips, a simple point lookup often completes in microseconds rather than milliseconds.
The table below summarizes the core components and the role each plays inside the process.
| Component | Function | Typical implementation |
|---|---|---|
| Storage layer | Organizes pages on disk | B-tree, B+ tree or LSM tree |
| Transaction manager | Guarantees atomic commits | Write-ahead log or rollback journal |
| Concurrency control | Coordinates readers and writers | File locks, MVCC or single-writer lock |
| Query layer | Parses and executes requests | SQL parser or key-value API |
| Cache | Keeps hot pages in memory | Page cache or OS memory mapping |
Main types of embedded engines
Embedded engines differ mainly in their data interface and storage structure, which determine the workloads they handle well. Relational engines offer full SQL, while key-value libraries expose only get, put and range scans but reach much higher write throughput.
| Category | Interface | Storage structure | Strong workload |
|---|---|---|---|
| Embedded relational | SQL | B-tree pages | General application state |
| Embedded key-value (B-tree) | Get, put, cursor | Copy-on-write B+ tree | Read-heavy lookups |
| Embedded key-value (LSM) | Get, put, iterator | Log-structured merge tree | Write-heavy ingestion |
| Embedded analytical | SQL | Columnar segments | Local aggregation and reporting |
| Embedded document | JSON-style API | Varies by engine | Offline-first mobile data |
The choice of structure creates a familiar trade-off. LSM trees favor writes by batching them into sorted runs but pay later through compaction and read amplification, whereas B-trees favor reads and predictable latency but rewrite pages in place or copy them on change.
Embedded databases compared with client-server systems
The key distinction from a client-server database is who owns the process: the application itself, rather than a dedicated server that many clients reach over a network. This shapes concurrency, security, operations and scaling.
| Aspect | Embedded database | Client-server database |
|---|---|---|
| Process model | Library in the application | Separate server process |
| Access path | Direct function calls | Network or socket protocol |
| Administration | Practically none | Installation, tuning, upgrades |
| Concurrent writers | Usually one at a time | Many simultaneous sessions |
| Access control | File system permissions | Users, roles and privileges |
| Scaling | Bounded by one machine | Replication and clustering |
An embedded database is also distinct from an in-memory database, a neighboring Term in this Topic. Many embedded engines persist data to disk, and many in-memory systems run as servers; the two properties are independent, although SQLite, for example, can operate in both modes.
When to choose an embedded database
An embedded database is the right choice when one application owns its data and needs local, durable, low-latency storage without operational overhead. It is a poor choice when many independent services must write the same dataset concurrently.
| Situation | Recommendation | Reason |
|---|---|---|
| Mobile or desktop app | Embedded relational engine | Offline access, no server to install |
| Edge device or router | Small key-value library | Low memory and flash footprint |
| High-rate event ingestion in a service | Embedded LSM engine | Fast sequential writes |
| Local analytics on files | Embedded columnar engine | Vectorized aggregation on one machine |
| Shared multi-user web backend | Client-server database | Many concurrent writers and remote access |
Configuration matters as much as selection. Practitioners typically enable write-ahead logging, set an appropriate synchronization level, size the page cache to the working set and wrap batches of inserts in explicit transactions, which can raise insert throughput by one to two orders of magnitude compared with autocommit.
Limitations and common mistakes
The main limitation of an embedded database is write concurrency: most engines allow only one writer at a time per file, so heavy parallel writes serialize. Other constraints follow from the single-process, single-machine design.
- Network file systems such as NFS or SMB often break file locking and can corrupt data; keep database files on local storage.
- Long-running read transactions prevent log checkpoints or old page reclamation, so files grow unexpectedly.
- Copying a live file without the engine’s backup API can produce an inconsistent snapshot.
- Schema migrations ship with every application release and must handle all older versions found on user devices.
- No built-in replication in most engines means backup and synchronization are the application’s responsibility.
- Encryption at rest usually requires an extension or a separately licensed build.
A frequent misconception is that embedded means toy or low-capacity. Mature embedded engines handle databases of many gigabytes or more, provide full ACID transactions and are among the most widely deployed software components in existence.
In plain words
Most large databases work like a library building across town: programs travel there, ask a librarian and wait for the answer. An embedded database is more like a bookshelf built into the program itself. The data sits right next to the code, so reading and saving are fast and nobody has to run or look after a separate building.
The catch is that the bookshelf belongs to one program on one computer. It is ideal for an app on a phone or a gadget, but not for thousands of users editing the same records at the same time.
A real-world example
A field-inspection company builds a tablet app for engineers who check bridges in areas with poor mobile coverage. Each inspection holds about 200 measurements, photos and notes. The team uses an embedded relational database stored in a single file on the tablet, with write-ahead logging enabled and every inspection saved inside one transaction.
Engineers work fully offline for a whole day, recording around 40 inspections. When the tablet reconnects, a background job reads unsynchronized rows and uploads them to the central server. Because the local engine needs no installation or maintenance, the company rolls the app out to 300 tablets with no database administration effort, and a crash or sudden power loss never leaves a half-saved inspection, because the transaction either commits completely or not at all.