Imagine you're ordering something online.
You select the product.
Enter your details.
Click Place Order.
Nothing happens.
You wait two seconds.
Still nothing.
So you click again.
Suddenly, two orders appear.
Congratulations. You've just discovered a bug that can exist even when every individual function works perfectly.
And here's the interesting part.
The problem might not be the button, the API, or the database.
It might be the assumption that a request will only happen once.
I think this is one of those software engineering problems that looks incredibly simple until you start building real systems.
We Assume Users Will Behave Perfectly
Consider a basic order API.
@app.post("/orders")
def create_order(order: Order):
save_order(order)
send_confirmation_email(order)
return {"status": "success"}
At first glance, nothing looks particularly unusual.
Receive an order.
Save it.
Send a confirmation.
Return success.
But what happens if the same request arrives twice?
The application…