I thought FastAPI was fast. Turns out I was just using it wrong. Client called me one day. Why is the API so slow? I thought you said FastAPI is fast? I said yes. FastAPI is async. It handles concurrent requests beautifully. What I didn't say.... My routes weren't async at all. Here's what my code looked like: # What I wrote @app.get("/users/{id}") def get_user(id: int, db: Session = Depends(get_db)): return db.query(User).filter(User.id == id).first() Looks fine right? That def instead of async def — that one word was blocking FastAPI's entire event loop. Every request was waiting for the previous one to finish. Not concurrent. Not async. Just a very expensive queue. The fix was literally one word: # What it should have been @app.get("/users/{id}") async def get_user(id: int, db: AsyncSession = Depends(get_db)): result = await db.execute(select(User).where(User.id == id)) return result.scalars().first() def → async def Response time under load: 4 seconds → 200ms. The lesson nobody tells you clearly: FastAPI is only as async as you make it. The framework won't save you from blocking code. It just gives you the tools — you still have to use them correctly. → Always use async def for route handlers → Use httpx not requests inside async endpoints → Use AsyncSession not Session for DB calls One word. One month of slow APIs. One very unhappy client. #FastAPI #Python #BackendDevelopment #AsyncProgramming #SoftwareEngineering #LessonsLearned #WebDevelopment
Arsh Singhal’s Post
More Relevant Posts
-
One pattern that changed how I build FastAPI backends: Stop returning raw database models from your endpoints. When your API response mirrors your ORM model 1:1, you're creating tight coupling between your database schema and your API contract. One schema change can break every client. The fix: dedicated Pydantic response models per endpoint. Here's what you get: 1. Auto-generated OpenAPI docs that actually match your responses 2. A clear data boundary - internal fields stay internal 3. Freedom to refactor your DB without touching your API contract Bonus: Pydantic's model_validator and computed fields let you shape responses exactly how your frontend needs them - no extra serialization logic scattered across your codebase. What patterns have saved you the most headaches in your backend work? #Python #FastAPI #WebDevelopment #SoftwareEngineering #FullStackDeveloper
To view or add a comment, sign in
-
Asynchronous APIs ... Simple. If you've built with Flask, Starlette's mental model is familiar—routes, requests, responses. What changes is the foundation: Starlette is async-first, which means your server handles many requests concurrently without spawning threads. In Day 1, we go from zero to: ✓ A running local server with Uvicorn ✓ Two working API endpoints (GET routes) ✓ A POST handler that reads JSON and creates new tasks Plus: why async matters, why the async/await pattern is everywhere in Starlette, and what the request object actually gives you. No complex setup. Just fresh virtual environment + pip install starlette uvicorn + 30 lines of code that's already production-shaped. → Read the full Day 1 (of 5) Article here: https://lnkd.in/gRNJdhaz #Starlette #Python #ASGI #BackendDevelopment #APIDevelopment #Tutorial #linkedin
To view or add a comment, sign in
-
Stop writing manual validation logic In traditional frameworks, you spend a lot of time writing code like: if not data.get("email"): raise ValueError... With FastAPI, you stop writing "checks" and start defining Schemas. By using Pydantic models, FastAPI does the heavy lifting for you: ✅ Automatic Parsing: Converts incoming JSON directly into Python objects. ✅ Data Validation: If a user sends a string where an integer should be, FastAPI catches it instantly. ✅ Clear Errors: It sends a detailed 400 error back to the client automatically—your function logic doesn't even have to run. The result? Cleaner code, fewer bugs, and a backend that "just works." Check out the snippet below to see how 5 lines of code can replace dozens of if/else statements. #Python #FastAPI #Pydantic #WebDevelopment #Backend #CleanCode
To view or add a comment, sign in
-
🚀 FastAPI: Build Powerful APIs with Less Code If you're building APIs in Python and not using FastAPI yet… you're missing out. Here’s why FastAPI is gaining massive popularity 👇 ⚡ Blazing Fast Performance Built on ASGI and Starlette, FastAPI delivers performance close to Node.js and Go. 🧠 Automatic Data Validation Thanks to Pydantic, you get type validation using Python type hints — clean and powerful. 📄 Auto-Generated Docs Swagger UI & ReDoc are generated automatically. No extra effort needed. 🔐 Easy Authentication & Security Supports OAuth2, JWT, and other modern security standards out of the box. 🔧 Developer-Friendly Less code, more productivity. You write less boilerplate and focus on logic. 💡 Example: from fastapi import FastAPI app = FastAPI() @app.get("/") def home(): return {"message": "Hello FastAPI 🚀"} 🔥 Whether you're building microservices, AI APIs, or backend systems — FastAPI is a game changer. Start learning today and level up your backend skills 💪 #FastAPI #Python #BackendDevelopment #WebDevelopment #APIs #Programming #SoftwareEngineering #100DaysOfCode #DeveloperLife #Coding
To view or add a comment, sign in
-
🚀 Built & Deployed a FastAPI REST API Excited to share that I’ve been working on building high-performance REST APIs using FastAPI! 🔹 Designed scalable API endpoints 🔹 Implemented CRUD operations 🔹 Integrated request validation using Pydantic 🔹 Ensured high performance with async support 🔹 Tested endpoints using Postman FastAPI makes backend development faster, cleaner, and more efficient compared to traditional frameworks. Currently exploring deployment strategies and integrating APIs with AI/LLM-based applications 🤖 #FastAPI #RESTAPI #BackendDevelopment #Python #APIDevelopment #AI #MachineLearning
To view or add a comment, sign in
-
FastAPI — Why It’s Becoming a Favorite for Backend Development FastAPI is a modern Python framework used to build APIs quickly and efficiently. But it’s not just another framework. It’s designed for speed, simplicity, and performance. What is FastAPI? FastAPI is a web framework for building APIs using Python, based on modern standards like type hints. It helps developers write less code and build faster, reliable APIs. Key Features: High performance (comparable to Node.js and Go) Automatic data validation using Python types Auto-generated API documentation (Swagger UI) Built-in async support Easy integration with databases and tools Example Use Cases: Building REST APIs Backend for web and mobile applications AI/ML model APIs Microservices architecture Why developers prefer FastAPI: Clean and readable code Faster development time Strong typing reduces bugs Suitable for scalable systems Final Insight: FastAPI is not just about building APIs faster. It’s about building APIs the right way. Follow Saif Modan #Python #FastAPI #Backend #API #Tech #AI
To view or add a comment, sign in
-
-
Python devs: scrape any website in 3 lines. from crw import CRW crw = CRW() result = crw.scrape("https://example.com") That's it. Clean markdown output. Ready for your LLM pipeline. No Selenium. No Playwright. No browser dependencies. No chromedriver hell. pip install crw What you get: - Clean markdown from any URL - Structured data extraction - Full site crawling - Site mapping - Web search Under the hood: Rust-native engine. 833ms per page. 6.6MB RAM. The Python SDK calls CRW's Firecrawl-compatible API. Same power. Same speed. Python simplicity. Works great with: - LangChain - LlamaIndex - CrewAI - Any LLM framework expecting markdown input 92% page coverage. 85ms cold start. Stop wrestling with browser automation. Start scraping. #Python #WebScraping #DevTools #AI #OpenSource https://fastcrw.com github.com/us/crw
To view or add a comment, sign in
-
-
🎯 Precision Engineering: Beyond Basic Queries "A great API doesn't just give you data—it gives you the right data, or a clear reason why it can't. 🛡️ Today I expanded my TodoApp by implementing Path Parameters. Moving beyond fetching 'all' records, I’ve added logic to retrieve specific tasks by their ID. Key technical highlights from this update: ✅ Input Validation: Used FastAPI’s Path to ensure only valid IDs (greater than 0) are processed. ✅ Robust Error Handling: Integrated HTTPException to return a clean 404 Not Found status if a user requests an ID that doesn't exist. ✅ Clean Code: Refactored using Annotated dependencies to keep the route handlers lean and readable. Building a backend isn't just about the 'Happy Path'—it's about handling every edge case with precision. Next: Implementing POST requests to allow users to create their own tasks! 🚀" #FastAPI #Python #BackendDevelopment #WebAPI #CleanCode #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 FastAPI 𝗷𝘂𝘀𝘁 𝘂𝗻𝗹𝗼𝗰𝗸𝗲𝗱 𝘀𝗼𝗺𝗲𝘁𝗵𝗶𝗻𝗴 𝗯𝗶𝗴. With FastAPI 0.136.0 officially supporting free-threaded Python (No-GIL), I wanted to move beyond the hype and measure what actually changes in real-world APIs. So I ran controlled benchmarks comparing: • Python 3.12 (GIL) • Python 3.13.0t (No-GIL) Same code. Same FastAPI app. Zero changes to the source. 🔬 How I benchmarked it: I isolated CPU-bound workloads — the kind that the GIL historically serializes — and hit the endpoints with concurrent requests using a fixed thread pool. Both environments ran on identical hardware with warm-up rounds to eliminate JIT noise. No async tricks, no multiprocessing — pure threading, the way most real backends actually work. 💥 Result: ~8× improvement in CPU-bound throughput under concurrency. This isn't just a micro-benchmark win. It directly impacts: • ML inference APIs serving parallel requests • Data processing and transformation workloads • CPU-heavy backend systems under real load I've broken down the full experiment, setup, and results here: 👉 Medium Post : https://lnkd.in/guUZEyiV Curious — are you already running experiments with free-threaded Python, or waiting for broader ecosystem support? 👇 #FastAPI #Python #Performance #Backend #Concurrency #AI
To view or add a comment, sign in
-
-
🚀 I just built and deployed my first AI-powered Web Application! I wanted a faster way to extract value from long documents, so I built an AI Book Summarizer. You can drag and drop any PDF or text file into the app, and it instantly generates an Executive Summary, Key Themes, and Actionable Takeaways. I even added a chat feature so you can ask the document specific questions! Tech Stack: Python, Streamlit, and Google's new Gemini 2.5 Flash model. You can try it out live right here: [https://lnkd.in/gBC65w3T] Want to see how it works under the hood? Check out the code: [https://lnkd.in/guDPNYb7] I'd love to hear your feedback or see what documents you test it with! #Python #ArtificialIntelligence #GeminiAPI #Streamlit #SoftwareDevelopment #Portfolio
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development