Menu

FastAPI with PostgreSQL on a free tier: one worker, a capped async pool, and the connection limits that bite
📰

FastAPI with PostgreSQL on a free tier: one worker, a capped async pool, and the connection limits that bite

DEV Community: fastapi·SnapDeploy·4 days ago
#qWBzX9L6
#devtofastapi#devto#dev#container#postgresql
Long article (1205 words) — no AI summary yet.
Reading 0:00
15s threshold

TL;DR: On a quarter of a CPU one Uvicorn worker beats four, and a capped async connection pool is what keeps a 50-connection database happy. Migrations at start, a health route that survives a sleeping container, CORS against the container hostname, and the free and $1 options for the PostgreSQL itself. Tested on Python 3.12 with SQLAlchemy 2 and asyncpg.

FastAPI is the framework people reach for when they want an API up this afternoon, and it deploys well on a small container because it is asynchronous: one process can hold hundreds of open requests while it waits on the database. This guide takes a FastAPI service with PostgreSQL to a free container tier, with the async database setup done properly, the worker count that actually fits a quarter of a CPU, and the connection limits you will hit if you copy a tutorial written for a bigger box.

Tested on Python 3.12 with SQLAlchemy 2 and asyncpg.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.