Bird
0
0

Given this FastAPI code snippet using SQLAlchemy with connection pooling, what happens when multiple requests come in simultaneously?

medium📝 component behavior Q4 of 15
FastAPI - Database Integration
Given this FastAPI code snippet using SQLAlchemy with connection pooling, what happens when multiple requests come in simultaneously? ```python engine = create_engine("postgresql://user:pass@localhost/db", pool_size=3, max_overflow=2) SessionLocal = sessionmaker(bind=engine) @app.get("/items") async def read_items(): db = SessionLocal() items = db.query(Item).all() db.close() return items ```
AOnly 3 connections total are allowed, others fail immediately
BUp to 5 connections can be used concurrently before requests wait
CEach request creates a new connection ignoring pooling
DRequests queue indefinitely without limit
Step-by-Step Solution
Solution:
  1. Step 1: Understand pool_size and max_overflow meaning

    pool_size=3 means 3 persistent connections; max_overflow=2 allows 2 extra temporary connections.
  2. Step 2: Calculate max concurrent connections

    3 + 2 = 5 connections can be used at once before requests wait.
  3. Final Answer:

    Up to 5 connections can be used concurrently before requests wait -> Option B
  4. Quick Check:

    Max concurrent connections = pool_size + max_overflow [OK]
Quick Trick: Max connections = pool_size + max_overflow in SQLAlchemy [OK]
Common Mistakes:
MISTAKES
  • Assuming max_overflow connections are not allowed
  • Thinking requests fail immediately when pool is full
  • Believing each request ignores pooling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes