When orders need to flow from customer to kitchen in under a second, REST APIs aren't enough. Here's how I built real-time order tracking for a cloud kitchen platform.
Architecture Overview
Client → Socket.io → Redis Pub/Sub → Kitchen Display
↓
PostgreSQL (persistence)The Challenge: State Consistency
The hardest part wasn't WebSockets — it was keeping order state consistent across multiple kitchen stations viewing the same queue.
typescript
// Order state machine
const orderStates = {
PLACED: ['ACCEPTED', 'REJECTED'],
ACCEPTED: ['PREPARING'],
PREPARING: ['READY'],
READY: ['PICKED_UP'],
} as const;
function canTransition(current: OrderState, next: OrderState): boolean {
return orderStates[current]?.includes(next) ?? false;
}In real-time systems, the bug isn't usually in the WebSocket layer. It's in the state management.