
SQLite in Production: WAL Mode on the Factory Edge
Default SQLite blocks dashboard reads whenever a background write happens, and one pragma fixes it.
- Published
- February 16, 2026
- Author
- Hrushiekesh Reddy Kanjula
- Read time
- ~4 min
- Category
- engineering

Our MES dashboard froze every 30 seconds. A background Python scheduler polls the machine APIs on that interval and writes telemetry to SQLite. In default mode, each write blocks every reader. The live dashboard hitched on every poll.
The usual conclusion is that SQLite can't handle concurrent work and we need a bigger database. I wouldn't agree with that. The fix is one line: enable WAL mode.

What WAL mode changes
Default SQLite uses a rollback journal. When one connection writes, readers wait.
WAL stands for write-ahead logging. Changes go to a separate log file first. Readers keep querying the last committed state while the writer appends to the log. Reads and writes stop blocking each other.
conn.execute("PRAGMA journal_mode=WAL;")WAL still allows only one writer at a time. For us that is fine. One telemetry scheduler writes, and several dashboard queries read. That is the data flow we wanted anyway.
Why not PostgreSQL
PostgreSQL is a good database. It is the wrong fit for this machine. Our MES runs on edge hardware bolted to the factory floor next to the SMT line. Manufacturing engineers run it, and they shouldn't have to administer a database.
PostgreSQL needs a running daemon, port configuration, a superuser account and a cluster initialization step. It also needs ongoing maintenance such as vacuuming, WAL archiving and connection pooling. SQLite is a single .db file. The application is the server. There is no daemon and no network port. Backup is cp factory.db factory.db.bak.
The other pragmas
WAL is the main change. Four more settings matter in a production configuration.
| Pragma | What it does |
|---|---|
PRAGMA synchronous = NORMAL | In WAL mode, this gives good durability without the cost of FULL sync. The database survives application crashes. Only an OS crash during a checkpoint could theoretically lose data, and the WAL file still provides recovery. |
PRAGMA cache_size = -64000 | Sets a 64MB page cache. This cuts disk I/O for frequent dashboard queries over millions of rows. The negative sign means the value is in kilobytes. |
PRAGMA foreign_keys = ON | Off by default. Turn it on every time. |
PRAGMA busy_timeout = 5000 | Waits up to 5 seconds before raising "database is locked". Without it, concurrent writes raise exceptions immediately and the app needs its own retry logic. |
Connections in Python
Python's sqlite3 module ties a connection to the thread that created it, and connection objects are not thread-safe. Sharing one connection across threads causes race conditions.
So each thread gets its own connection to the same database file. The background scheduler thread holds one. The Eel WebSocket handler threads hold their own. WAL keeps them from blocking each other, and SQLite's locking coordinates the rest.
This is simpler than a PostgreSQL pool with asyncpg or psycopg3. It also matches the scale. A factory-floor MES handling a few hundred writes per minute doesn't need a pool built for thousands of web users.

The benchmark
After the WAL setup, I ran a simple stress test on a mid-range Intel NUC: 500 concurrent read queries against 10 simultaneous background writes. Read latency averaged under 10ms even under write pressure. The dashboard queries that used to hitch rendered smoothly, and the UI thread never blocked.
Then I ran the equivalent workload on a local PostgreSQL instance on the same hardware.
| SQLite with WAL | PostgreSQL | |
|---|---|---|
| Configuration time | 5 minutes | 45 minutes |
| Performance | Within 15% of PostgreSQL | Marginally faster at peak throughput, after accounting for daemon startup and connection overhead |
For a single edge device, I don't see a reason to take on the extra setup.
When SQLite is the wrong answer
If several machines need to write to one database over a network, the single-writer model breaks down. Use a client-server database. If you run complex analytical queries over hundreds of gigabytes, use a column store such as DuckDB or a dedicated analytics engine.
For a single-machine MES with one writer and several readers, SQLite with WAL is the right architecture.

The assembly hub's whole data layer sits on this. The schema design comes next: three cascading tables that cover everything from BOM imports to machine telemetry.