Designing a Fast, Scalable, and Fault-Tolerant Create Order Process
When users click "Create Order", they expect one thing: speed. But behind that single click often lies a chain of database writes and external API calls that quietly slow everything down. This article shows how a simple event-driven approach can turn a slow, fragile order flow into one that is fast, scalable, and resilient β without overengineering.
π― "Why is my create order so slow?"
This is a classic question that shows up as a system starts to grow. Take a closer look and that seemingly simple create order flow often hides a lot of work behind the scenes:
- Save the order to the database
- Call a logistics API to generate a tracking number (AWB)
- Call a WMS (Warehouse Management System) API to request shipment
It looks like just three steps. But when they run synchronously, users can end up waiting 3β10 seconds. Even worse, if an external API is slow or down, the entire process fails with it.
This is the point where many developers realize something important:
"Not every process has to finish before the user gets a response."
The solution: Event-Driven Architecture.
π Why event-driven architecture is a great fit
Because it allows us to clearly separate:
- Lightweight steps β synchronous
- Heavy steps β asynchronous
The result: fast user responses, stable servers, and external APIs that no longer block critical requests.
π End-to-end flow: from click to warehouse
1. User clicks "Create Order"
The backend receives the request.
2. The system does only what truly matters
- Validate input data
- Persist the order to the database
- Publish the
ORDER_CREATEDevent
Processing time: extremely fast (50β150 ms).
3. The user immediately gets a response
"Order successfully created."
4. Background workers handle the rest, asynchronously
Logistics processor:
- Listens to the
ORDER_CREATEDevent - Calls the logistics API
- Generates the tracking number (AWB)
- Updates the database
- Publishes the
AWB_GENERATEDevent
WMS processor:
- Listens to the
AWB_GENERATEDevent - Calls the WMS API
- Updates the order status (e.g., Ready for Fulfillment)
All of this happens in the background. The user never has to wait.
π Benefits of this architecture
Much better user experience
Requests are no longer blocked by external APIs.
Loose coupling with vendor reliability
If the logistics API is down, the worker retries. The order itself already succeeded.
Horizontally scalable
Traffic increases? Just add more workers.
Fault-tolerant by design
Queues, retries, DLQs, and idempotency keep the system safe.
π§± Critical pieces to make this production-ready
1. Idempotency
Events can be delivered more than once. Workers can crash. Networks can time out.
You must ensure:
- Tracking numbers are not generated twice
- WMS requests are not sent twice
- Order status is checked before processing
Common approaches: status columns, event log tables, and the outbox pattern.
2. Retry with exponential backoff
Avoid retrying every second. Use a pattern like:
1s β 5s β 20s β 60s β DLQ
If it still fails, move the message to a Dead Letter Queue for investigation.
3. Reasonable timeouts
External APIs are unpredictable. My recommendations:
- 3β5 second timeouts on external calls
- Never let workers block for too long
4. Observability
You need visibility into:
- How many events are in the queue?
- Which workers are failing?
- How long have external APIs been down?
Logs, metrics, and distributed tracing cover all three.
π Why this approach saves so many developers
By moving heavy processes into background workers:
- Users never wait too long
- Servers don't get overwhelmed
- Orders don't fail just because a logistics API is broken
- Developers can focus on building features instead of fighting fires
In short:
"Do what matters now. Let the patient workers handle the rest."
π Conclusion
A powerful order system doesn't have to be complex. By clearly separating synchronous and asynchronous responsibilities, you can build a system that is fast, scalable, fault-tolerant, and easy to evolve. Event-driven architecture provides exactly that foundation.
If you're building e-commerce platforms, marketplaces, logistics systems, or any kind of transactional system β this pattern is one of the best long-term investments you can make.
Happy coding π