Why your Rails monolith feels like it’s “suffocating” – and when FastAPI actually makes sense?

Your Django or Ruby on Rails monolith has probably been running fine for years, reliably generating revenue with minimal drama. Then traffic spikes – maybe after a successful marketing campaign – and suddenly everything starts slowing down. Requests time out, servers struggle, and scaling becomes expensive fast. The first thought of hot-headed people in the […]

Category

Technologies

Posted

Nikita

Aug 27, 2026

Your Django or Ruby on Rails monolith has probably been running fine for years, reliably generating revenue with minimal drama. Then traffic spikes – maybe after a successful marketing campaign – and suddenly everything starts slowing down. Requests time out, servers struggle, and scaling becomes expensive fast.

The first thought of hot-headed people in the team: “Let’s throw everything out and rewrite from scratch!” Please don’t do this. A complete rewrite of a large system is the shortest way to burn through the budget and miss deadlines.

How to make the transition painless for business? Use the Strangler Fig pattern. In practice, it looks like this: you put Nginx or Traefik in front and start carefully “biting off” the most loaded pieces from the monolith. Found an endpoint that processes thousands of analytics requests per minute? Move it separately to FastAPI. The old logic continues to work, and you gradually, without any stress, transfer the infrastructure to the new rails.

Waiter in the kitchen: What is the magic of ASGI?

Why FastAPI?

The whole trick is in the transition from WSGI to ASGI. Imagine a waiter in a restaurant (this is our traditional synchronous server). He came to the table, took the order and stands waiting for the chef to prepare the dish. The other tables are starving. Absurd, right? But that’s how a classic server works.

But ASGI and Event Loop in FastAPI work differently. The waiter gave the order to the kitchen and instantly ran to serve the next customer. As soon as the first dish is ready, he picks it up. Thanks to the async/await paradigm, one FastAPI process can hold thousands of concurrent connections at the same time. The speed is impressive – it almost approaches Go or Node.js.

Contracts that make developers happy

Forget about the times when front-end developers came shouting: “You changed the JSON format again!”. Thanks to Pydantic V2 in FastAPI, your data schemas are a reinforced concrete law. Moreover, since the Pydantic V2 core is written in Rust, data validation works up to 20 times faster than in the first version.

You simply describe the class, and FastAPI automatically generates interactive Swagger documentation. No manual writing. And the Dependency Injection system here is the best in the Python ecosystem. It allows you to elegantly juggle asynchronous database sessions (for example, SQLAlchemy) and replace them in tests in a matter of seconds.

Docker in production: Don’t step on the rake

Of course, you also need to be able to deploy all this. If you just write pip install in a Docker file, your image will weigh a gigabyte. Who needs that? Use multi-stage builds. We collect dependencies in one temporary container, and only throw the clean result into the final image.

Here’s what an adequate Dockerfile for real life looks like:

Pay attention to the last line. Running Uvicorn alone in Kubernetes under heavy load is a bad idea. Pairing Gunicorn (as a master process to manage workers) with Uvicorn (as a super-fast ASGI worker) gives incredible stability. This way you get a true zero-downtime deployment, and your phone won’t be interrupted by notifications from the monitoring system in the middle of the night.

At Swan Software Solutions, we are proud to help clients with their technology needs. Discover more about how our team could help your team by scheduling a free assessment.