DEV Community

Khyati Tiwari
Khyati Tiwari

Posted on

Is FastAPI the best choice to build a Backend Entry Point?

Starting with placements around last year, the first project I built was a FastAPI-based API gateway. Essentially, what the gateway ensures is that only authenticated traffic reaches backend services alongside enforcing traffic control and observability standards.

It handles authentication, rate limiting, logging, and request routing before forwarding traffic to internal services and I'm not just naming features, they help solve some major pain-points while building a reliable backend.

  1. Mobile and web apps have to keep track of multiple URLs and if you move a service to a new server, you have to update the client-side code and force a redeploy.
    Now, because of the routing and proxying feature, there is only one URL. Moreover, the Gateway acts as the traffic controller, mapping requests to the right place.

  2. Each microservice has the same authentication logic and if a security vulnerability is found in how you verify tokens, you have to patch and redeploy every service in your ecosystem.
    The Gateway verifies the JWT once. If it’s valid, it passes the request to the backend with a header. As a result, the backend services can focus purely on business logic instead of security.

  3. A single user/script bug can send 10,000 requests per second — crashing the database and causing DOS for all other users.
    The Gateway counts requests in real-time and as soon as a user crosses their limit the gateway returns an HTTP Status 429.

  4. Digging through five different sets of server logs across five different machines to piece together what went wrong with an error.
    Every request sent is logged in a consistent format at the entry point including the full path, the response time, and the status codes improving debugging speed by 10x.

  5. You don’t know your system is slow until support tickets are raised, no data on peak traffic hours or which services are struggling.
    A real-time dashboard. You can see the heartbeat of your system. For example, if your average response time climbs from 50ms to 500ms, an automated alert can notify you before the system crashes.

I chose FastAPI because of concurrency. Since the gateway waits for the backend to respond, FastAPI’s asynchronous capabilities allow it to handle these waiting states without the consumption of any extra memory.

What my concern is whether this API Gateway is truly good enough to be used in production-grade applications. Am I missing some features or issues that arise with handling backend systems? I would love some opinions.

You can test the API Gateway here : https://github.com/khyahahati/api-gateway

Happy to hear your thoughts!

Top comments (0)