Sohan Basak

Why I Bid Farewell to Express and Embraced FastAPI

an image containing a datacenter and a frustrated cat dealing with all the bytes in

Why I Bid Farewell to Express and Embraced FastAPI

As an AI Application Developer, I’ve danced with a variety of frameworks across the digital floor. From the cozy waltz with Express to the energetic tango with Koa and the swift moves of Fastify, my journey has been nothing short of a grand ball. But every dance comes to an end, and recently, I found a new partner: FastAPI. Let me take you through my journey, spiced with a dash of humor and a lot of technical insights.

The Papercut Problem:

In my previous company, maintaining our codebase felt like trying to organize a library run by cats—chaotic, full of small issues, and constantly in need of attention. Here’s a brief on the papercuts:

Documentation Maintenance

Regularly updating API documentation was essential but time-intensive, demanding precise tracking of changes in API endpoints and parameters to prevent discrepancies.

Postman Collections & Client Libraries

Creating and updating Postman Collections and client libraries required substantial effort to ensure they remained consistent with our APIs, a process that was both demanding and critical for seamless integration.

Schema Validation with @hapi/joi

Employing @hapi/joi for input validation offered robustness but maintaining synchronization between the schemas and documentation was challenging, emphasizing the intricacies of API contract management.

Legacy Code Challenges

Addressing legacy code without input validation involved navigating complex, deeply nested conditional logic, posing significant risks of bugs and security issues due to the lack of structured validation.

Performance Optimization via Fastify

Migrating over 100 services to Fastify was motivated by performance gains and cost reductions. This process highlighted the effectiveness of selecting frameworks that align with our performance objectives.

Non-Serverless Architecture Management

Handling configurations, deployments, and versioning in a non-serverless environment without dedicated DevOps was complex, underlining the benefits of serverless architectures for operational efficiency.

A New Beginning with FastAPI

Then came a shift in my career, offering me a clean slate to design systems from the ground up. With a need for speed, no dedicated DevOps, and the freedom to experiment, I chose FastAPI as my new dance partner. Here’s why:

  • Experimental Excitement: We were on a mission to find our product-market fit, which meant we had to be flexible and adaptable. Think of it like trying to build a ship while sailing the high seas – exciting, but definitely not for the faint of heart.
  • Speed Demons: We needed to move fast, like, REALLY fast. We were talking cheetah speed, not sloth speed. If we didn’t, we risked getting lost in the ever-changing tech landscape.
  • DevOps Doldrums: We didn’t have a dedicated DevOps team, which meant things like scaling, alerting, and monitoring had to be as close to plug-and-play as possible. Otherwise, we’d be drowning in operational overhead before we even had a chance to release a single feature.

Enter FastAPI: The Knight in Shining Armor

After much deliberation (and maybe a few late-night Google searches), I decided to give FastAPI a try. And let me tell you, it was like finding the missing piece of the puzzle. Here’s what sealed the deal:

Pydantic Magic

FastAPI’s use of Pydantic for type validation and schema management felt like finding a GPS after being lost at sea. It was intuitive, expressive, and allowed us to separate the wheat from the chaff in our code.

Documentation Generation

Creating documentation with FastAPI is as effortless as breathing—assuming you’re not underwater. The OpenAPI v3 specifications it generates turned what used to be a Herculean task into a leisurely stroll.

OpenAPI & Client Libraries

The ease of importing specifications into tools like Postman or generating client libraries felt like FastAPI was handing out cheat codes for developer happiness.

Async Await: The Game Changer

Having dabbled in the async-await sorcery of the JavaScript world, finding this in FastAPI was like discovering your favorite childhood snack at the grocery store as an adult.

Built-in Features

FastAPI came loaded with features like OAuth, multipart forms, and file uploads, making it feel like a Swiss Army knife in a world of plastic sporks.

Embracing Serverless with FastAPI

Deploying FastAPI applications in a serverless environment transforms our approach to scalability and management. By containerizing FastAPI and leveraging platforms like Google Cloud Run, AWS Lambdas, or AWS Fargate, we unlock the door to effortless scaling and reduced operational costs. This method seamlessly integrates with the serverless ecosystem, allowing our applications to dynamically adjust to load, ensuring efficiency and performance. The process is akin to setting sail on a self-navigating ship, where the complexities of the sea are managed by the vessel itself, letting us focus on the horizon ahead. With FastAPI in a serverless world, we step into a realm of streamlined deployments and operational simplicity, proving once again that the future of application development is not just about writing code, but also about how and where it runs.

And Then Came AI

My pivot to building AI and LLM-driven applications like AIYO and ALLY (will be announced soon) revealed even more of FastAPI’s strengths:

  • Python Integration: Being the lingua franca of AI, Python’s integration with FastAPI was like peanut butter meeting jelly.
  • First-class SDK Support: SDKs from giants like OpenAI felt tailor-made for FastAPI, simplifying our development process.
  • SSE & Streaming Responses: Building responsive chatbots with SSE instead of websockets is significantly simpler, imagine SSE being a tesla and websockets being a koenigsegg — we are on a highway, not a racetrack.

Wrapping up

Switching to FastAPI wasn’t just a technical decision; it was a strategic move towards simplification, efficiency, and embracing the future of AI development. While the journey with my previous technology stack was memorable, FastAPI has proven to be a dance partner that keeps in step with my evolving needs.

So, to my fellow developers standing at the crossroads of framework choices, consider this not as marketing fluff (as I don’t even know the guy who made it) but as a tale from the trenches. FastAPI might just be the framework you didn’t know you were searching for. And remember, in the grand dance of development, choosing the right partner makes all the difference.

Subscribe Sohan's weekly Newsletter

One update per week. All the latest news directly in your inbox.