When should I move a small Flask app from SQLite to PostgreSQL?
Asked by
Percussionist
I built a small game as a learning project using Flask for the API, SQLite for storage, and a lot of JavaScript for the game logic. Everything currently works, but I'm unsure when it makes sense to refactor the code or replace SQLite with a more traditional production database.
My current instinct is to wait until a real limitation appears instead of upgrading preemptively. What signs or operational requirements usually indicate that it's time to change databases?
Answers
Make the eventual migration easier now by using an ORM or a small data-access layer, keeping queries and database-specific logic in one place, and using schema migrations. Then moving to PostgreSQL later is much less disruptive. Just remember that an abstraction layer doesnโt hide every difference, so test important queries against the target database before switching.
Reply to this answer
SQLite can absolutely be suitable for production, especially for a small application. The important question is whether your workload matches its limitations: the database is a local file, writes are serialized, and multiple application servers canโt safely share the same file. WAL mode can help with concurrent reads and writes. Consider moving when you need several app instances, frequent concurrent writes, or hosting with temporary storage that could lose the database during a redeploy.
Reply to this answer
Waiting for a measured problem is usually better than migrating just because SQLite has a reputation for being unsuitable for production. Set up monitoring for response times, database errors, connection problems, disk usage, and backup health. If one of those signals stays above a threshold, investigate and profile the application before changing the stack. Sometimes an index or a code fix solves the issue more cheaply than a database migration.
Reply to this answer
Some developers start with PostgreSQL in Docker even for small projects because it keeps local and hosted environments closer to each other. Thatโs a reasonable choice if you already know youโll need multiple instances or PostgreSQL-specific features, but it isnโt required simply because the application is public.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Percussionist: I tested it at roughly 420 requests per second, and the largest number of concurrent users so far has been around 12. I donโt expect the project to reach a scale where request volume is a problem anytime soon.