LOG 004 · TECHNICAL · 2020-08-10
Rebuilt the Goodpods API from Django to FastAPI, endpoint by endpoint
2 min read
Situation
Goodpods is a social podcast app, and its original Django backend had been written by a single developer who then left. It had very little documentation and very poor performance. Even after architecture changes I had already made, it could only handle about 50 concurrent users, largely because it did many inefficient lookups against a podcast episode table that had grown to millions of rows. The business needed the platform to handle at least 500 concurrent users.
Task
I proposed a rewrite, and leadership sponsored it on one condition: it had to be a parallel rewrite, not a big bang. I led the work with two other backend developers, while also maintaining the original Django system throughout.
Action
I chose FastAPI with SQLAlchemy over staying on Django. We were not using the Django admin panel, so we lost nothing there, and FastAPI gave us async support for better concurrency, Pydantic schemas (typed request and response models), and auto-generated API docs so the frontend team could read the documentation instead of asking how endpoints worked.
In August 2020 I stood up the new service alongside the Django monolith, with its own Docker container and its own UAT and production deploy pipelines, so it could ship independently from day one. I built typed SQLAlchemy models for every table, added Alembic for database migrations, and set up a test suite using Postgres factories with a per-test rollback pattern.
The migration strategy was endpoint by endpoint: every time we touched a feature, I rebuilt it in FastAPI and fixed its inefficiency problems as part of the move. Auth and the follow logic were among the first to cross over.
Result
The cutover ran without major incidents; the one user-facing effect was that everyone had to log in again when auth moved. The two systems coexisted for about 12 months, then Django was entirely removed. The platform went on to handle 1500 concurrent users and over 2 million requests per day on average, three times the original 500 target. The folder structure and per-test rollback pattern from that rewrite are still in use today.