AI & Machine Learning 5 min read 49 viewsReviewed

One Process, One Server, SQLite: Debuggable Stack Lessons

A solo developer runs a multi-tenant SaaS on a 1 vCPU VPS with SQLite and 38 MB RAM. The real lesson is a decision rule for infrastructure: every piece you add is a piece you must debug alone at 11pm. Here is what SQLite gives you, what it costs, and when to move on.

One Process, One Server, SQLite: Debuggable Stack Lessons

A solo developer runs a multi-tenant SaaS for auto repair shops on a single 1 vCPU, 2 GB Ubuntu VPS. The web server, billing, email, and nightly backups all run in one Python process using 38 MB of RAM. The database is SQLite, with one file per shop plus a control-plane database. The post is explicit about where this stops working.

In this article (5)Expand ↓

What happened

The developer described running a small SaaS for independent auto repair shops with no DevOps help. The whole application runs as a single Python process on one server. Instead of a shared Postgres database with a tenant_id column, the design uses one control-plane database and one SQLite file per shop. The stated goal is not scale but being able to debug the system alone at 11pm. Every piece of infrastructure added is a piece the developer must understand, upgrade, and pay for.

Why it matters to you

If you are building a side project or a small SaaS, you will face the same choice: add a service or keep it simple. The default advice is to reach for Postgres, Redis, a queue, and a separate worker process. Each of those is another thing that can fail at night. Each is another dashboard to check, another version to upgrade, another set of credentials to rotate. The solo developer's rule is to ask "can I do without it?" before asking "is this the best tool?" That rule changes what you build.

SQLite is not a toy. It gives you real transactions, a file you can copy, and a query language you already know. For a side project with one writer at a time, it is often enough. The tradeoff is write concurrency: SQLite allows many readers but only one writer at a time. That is fine for a small SaaS with low write volume. It is not fine for a busy multi-tenant app with concurrent writes from many users.

The other cost is backup discipline. A single file is easy to copy, but copying a live SQLite file while it is being written can produce a corrupt backup. You need to use the backup API or ensure no writes are happening. If you use WAL (write-ahead logging) mode, the database file alone is not enough; you also need the -wal and -shm files, or you need to checkpoint before copying.

A per-tenant file design adds its own complexity. You get isolation: one shop's data cannot leak into another's query by accident. But cross-tenant queries become harder. Schema migrations must run on every file. You need a registry of tenants and a way to open the right file per request. The developer's control-plane database holds shops, users, and subscriptions, while each shop's data lives in its own file. That is a deliberate tradeoff, not a free lunch.

For a beginner, the lesson is not "use SQLite everywhere." The lesson is to count the cost of each component. A managed Postgres instance is one more service to learn, one more bill, one more place where connections can fail. If your project has a handful of users and low write traffic, SQLite may let you ship sooner and debug faster. If you expect many concurrent writers or need horizontal scaling, a client-server database is the right call. The evidence does not give a specific user count or write rate where SQLite breaks; you have to measure your own workload.

What to do about it

Start by writing down every infrastructure component in your project. For each one, ask: can I remove it without breaking a core feature? If yes, remove it. If no, write down why it is essential. This checklist forces you to justify complexity.

Next, if you are using SQLite, set up WAL mode and a safe backup. WAL mode lets readers and a writer work concurrently, which reduces blocking. But it creates extra files. The safe way to back up is to use SQLite's online backup API, which handles locking and consistency. Here is a runnable Node.js example using better-sqlite3 that enables WAL mode and performs a backup.

🟨JavaScript
const Database = require('better-sqlite3');
const fs = require('fs');
const path = require('path');

function openAndConfigure(dbPath) {
  const db = new Database(dbPath);
  db.pragma('journal_mode = WAL');
  db.pragma('synchronous = NORMAL');
  return db;
}

async function backupDatabase(sourcePath, destPath) {
  const db = openAndConfigure(sourcePath);
  try {
    await db.backup(destPath);
    console.log('Backup completed to', destPath);
  } catch (err) {
    console.error('Backup failed:', err.message);
    throw err;
  } finally {
    db.close();
  }
}

async function main() {
  const source = path.join(__dirname, 'app.db');
  const dest = path.join(__dirname, 'backup-' + Date.now() + '.db');
  if (!fs.existsSync(source)) {
    console.error('Source database not found:', source);
    process.exit(1);
  }
  await backupDatabase(source, dest);
}

main().catch((err) => {
  console.error('Unhandled error:', err);
  process.exit(1);
});

This example uses better-sqlite3, a synchronous SQLite library for Node.js. The backup method uses SQLite's backup API, which is safe while the database is open. Do not use fs.copyFile on a live database; that can copy a partial write and corrupt the backup.

For a per-tenant design, you would loop over tenant files. Keep a registry in your control-plane database. For each tenant, open the file, run the backup, and close it. Do this during low traffic if possible. Test restoring from a backup before you need it. A backup you have never restored is not a backup.

Finally, define your exit signals. Move to a client-server database when you see frequent "database is locked" errors, when write latency grows because of contention, or when you need multiple application servers. SQLite is a single-writer system; if your writes queue up, you have hit the limit. Also move when you need cross-tenant reporting that would require opening many files. The developer in the source post says he would stop doing it this way at some point, but the evidence does not specify the exact threshold. You have to watch your own metrics.

If you are building a small tool and want to compare persistence options, see our guide on Python persistence: when to move from JSON to SQLite. For a broader look at keeping systems debuggable, read The script ran. That is the weakest signal you have.

The decision rule is simple: every component you add is a component you must debug alone. If you can remove it, remove it. If you cannot, understand it deeply. That is what makes a system debuggable at 11pm.

Further reading

Sources

Share

About the Author

Comments (0)

Loading comments...