FlashDB: A Lightweight Embedded Database That Won’t Let You Down When the Power Goes Out
If you’ve ever worked with embedded systems that need to store data persistently, you know the struggle. One moment your device is happily logging sensor readings, the next the power cuts out, and boom — your database is corrupted, your configuration is toast, and you’re explaining to your boss why the thing bricks itself every time someone unplugs it.
That’s where FlashDB steps in. It’s a lightweight embedded database designed for flash storage, with built-in wear leveling and power-off protection. Think of it as a tiny, resilient key-value store that actually respects your flash chip’s lifespan.
What It Does
FlashDB is a database library optimized for embedded systems. It stores data on flash memory (NOR or NAND) with two modes:
- Key-Value mode — Simple string-based key-value storage, perfect for configs, settings, or small data logs.
- Time Series mode — Append-only logs organized by timestamp, ideal for sensor data or event records.
Under the hood, it handles wear leveling (spreading writes across flash sectors) and transactional power-off protection (so a crash mid-write doesn’t corrupt everything). It’s written in C, compiles to a tiny footprint, and runs on bare metal or RTOS.
Why It’s Cool
Most embedded databases either assume you have a file system or just ignore flash wear entirely. FlashDB is different:
- Wear leveling — It tracks erase counts and spreads data around so you don’t burn out one sector while the rest sit idle. Good for devices that write often.
- Power-off safety — Uses a journal-like mechanism. If power dies mid-write, it rolls back to the last valid state. No corruption, no mystery behavior.
- Tiny RAM footprint — Allocates memory dynamically based on what you store. No bloated buffers, no unnecessary overhead.
- No file system required — Works directly on raw flash partitions. Perfect for MCUs with small flash chips and no OS.
Use cases: smart locks saving access logs, IoT sensors batching readings, industrial controllers storing calibration data, or even your next hobby project that needs to survive random unplugging.
How to Try It
Clone it from the repo:
git clone https://github.com/armink/FlashDB.git
cd FlashDB
Then check the demo/ folder for examples on different MCUs (STM32, ESP32, Linux, etc.). The core library is just a few C files and a header you drop into your project.
Quick start on a Linux desktop:
make -C demo/linux
./demo/linux/fdb_demo
That runs a demo showing key-value and time-series writes and reads, with simulated power loss tests. You’ll see logs like:
[FlashDB] (fdb_kvdb_test) test write 'temp' = 45
[FlashDB] (fdb_kvdb_test) test read 'temp' = 45
[FlashDB] (fdb_tsdb_test) append timestamp 1234, value 5678
Read the docs/ folder for full API docs, and the port/ folder for customization (flash driver, lock, etc).
Final Thoughts
FlashDB doesn’t try to be a relational database or a fancy network-aware thing. It does one job — store data reliably on flash — and does it well. For anyone working with embedded hardware, especially battery-powered or power-uncertain devices, this is the kind of library you want in your toolbox.
If you’ve been stitching together your own weird flash storage hacks or relying on raw EEPROM, give FlashDB a spin. It might save you a headache (or a bricked device) down the road.
Found this on @githubprojects