Bird
0
0

What will happen if you save data only in a FastAPI variable without a database?

medium📝 Predict Output Q5 of 15
FastAPI - Database Integration
What will happen if you save data only in a FastAPI variable without a database?
items = []
@app.post('/add')
async def add(item: str):
    items.append(item)
    return items
AData will be saved to disk by FastAPI
BData will be lost when the server restarts
CData will be shared between different servers automatically
DData will be saved permanently
Step-by-Step Solution
Solution:
  1. Step 1: Identify storage type

    Data is stored in a Python list variable in memory.
  2. Step 2: Effect of server restart

    Memory clears on restart, so data is lost.
  3. Final Answer:

    Data will be lost when the server restarts -> Option B
  4. Quick Check:

    Memory storage = no persistence [OK]
Quick Trick: Variables lose data on server restart [OK]
Common Mistakes:
MISTAKES
  • Assuming FastAPI saves variables to disk
  • Thinking data shares across servers automatically
  • Confusing variable storage with database

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes