It sounds like this“Real software always uses a database; files are for amateurs.”

Thinking you must always use a database

2 min readBy the Cognosc teamPart of Why use a database instead of just saving files?

Why it feels right

Once you hear about lost updates, crashes and slow searches, a file starts to look like a trap. The professional advice sounds clear: use a database. For small projects it can start to feel like the only respectable choice, so a simple file becomes something to be embarrassed about.

Why it’s wrong

A file is fine for one user, a small amount of data and rare changes. Databases pay off with many writers, important data, lots of searching, or the need to recover from a crash. SQLite shows the line is blurry: it is a database kept in one ordinary file.

A worked example

A database brings a lot of machinery. You have to choose one, install and run it, design tables, learn a query language, and handle upgrades and backups. For a one-person recipe app with fifty recipes, none of this gives you anything you need. A single file that is loaded at the start and saved on exit is simpler, and easier to back up by copying.

What tips the balance is the problems from before: many people writing at once, data that must not be lost or half-saved, so much data that searching needs an index, or several kinds of record that must stay consistent with each other. If any of those is true, use a database. If none is, a file is a fair choice.

The line is also blurry. SQLite is a full database with transactions and indexes that lives in one ordinary file, which makes it a good middle path for small apps. Choose on what you need, not on what sounds serious.

How to catch yourself

  • You add a database server to a tiny, one-user app.
  • You feel a file is unprofessional.
  • You can't say which problem a database is solving for you.

What to hold instead

The better idea

A file is a fair choice for one user, small data and few changes. A database earns its cost with many writers, data that must survive crashes, or heavy searching. SQLite gives database guarantees in a single file.

Where you’ll meet it

  • Starting a small side project.
  • Reviewing a design that uses a heavy database for a tiny job.
  • Deciding when a project has outgrown its files.

Questions people ask

When is a file enough instead of a database?
When one user or process writes at a time, the data is small, it is mostly read, and losing the latest change is not a disaster. Then the simplicity of a file beats the cost of running a database.
What is SQLite?
A database engine that lives in a single file and runs inside your program, with no server. It has transactions, indexes and SQL, so it is a common step between a plain file and a full database server.

Where it’s taken apart

Caught by it?

Cognosc spots mistakes like this one.

It shows you what really happens, names the exact idea that led you off, and keeps checking you still understand the right one.