DEV Community

Ck-epsilon
Ck-epsilon

Posted on

I Built 4 FastAPI Projects in 2 Weeks — Here's What I Wish I Knew Before Starting

I just spent two weeks building 4 FastAPI backends back to back. REST API, web scraper + dashboard, React admin panel, AI workbench with CrewAI. 134 Python files. 38 tests. And 15 CI failures before a single green run.

Here's the messy part nobody talks about.


Docker Compose is a time sink

Every project. Same 5 containers. api, postgres, redis, celery, nginx. By project #3 I was copy-pasting docker-compose.yml and changing 3 variables. That's not engineering — that's clerical work.

I now keep a _templates/ folder. Copy the Docker skeleton, rename the project name, done in 30 seconds. If you're starting a new FastAPI project right now and don't have this, you're burning 3 hours on boilerplate.


migrations: users → roles → tokens. every. time.

I wrote this Alembic migration four times. Four. User table, role table, user_roles join, JWT token model. This isn't business logic. It's plumbing. Every backend needs it.

Now I have a base migration that creates all three in one alembic upgrade head. 30 seconds to working auth.


Celery is fine until you put it in Docker

Local dev: everything works. Docker: celery worker can't find the broker.

Turns out localhost:6379 works on your machine but inside Docker the Redis hostname is literally redis. Three projects in I learned two configs that prevent most Celery headaches:

worker_prefetch_multiplier=1 — one task per worker at a time, no worker starvation
task_acks_late=True — task stays in queue until it actually finishes, no data loss on crash

That's it. Two lines. Took me weeks to figure out.


CI failures are mostly not your fault

15 failures. Let me break them down:

  • pip install crashed because I forgot requirements.txt — twice
  • Syntax errors from an LLM merging two lines into gibberish — 4 times
  • Import errors from hallucinated PyPI versions — 3 times
  • Redis not running in CI — 3 times
  • Actual code bugs — 3 times

So 12 out of 15 had nothing to do with business logic. The CI was catching infrastructure problems. Green CI doesn't mean good code. Red CI doesn't mean bad code. It means you forgot to commit requirements.txt.


The real enemy is repetition

Across 4 projects I wrote Docker Compose once, CI once, Celery config once. But I wrote custom exception classes four times. Logging setup four times. Environment variable loading four times.

After project #2 I realized: every file I create should be a template for the next project. Not a workflow tip — survival.


Anyway, the template I ended up with is on GitHub. Docker Compose, Postgres, Redis, Celery, JWT auth, CI pipeline that actually passes (after 15 tries), and 38 tests. Fork it if you want. Saves you the 3 hours I blew on Docker setup.

Top comments (0)