Running two services end to end
Time to run both services together. Order Service on port 3000, Inventory Service on port 4000, Redis in the middle. Place an order and watch the Inventory Service deduct stock moments later with nothing but an event between them.
Three terminals: one for the Order Service, one for the Inventory Service, and one for curl. In production these would run in separate containers on separate hosts. Locally they are just three processes sharing the same Redis.
terminal
bash
# In terminal 3
TOKEN=$(curl -s -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"password123"}' | jq -r .token)
curl -X POST http://localhost:3000/api/orders \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"bookId":1,"quantity":2}'
# Check inventory
curl http://localhost:4000/inventory/1Place an order and watch the Inventory Service react in its own log.
Validation checklist: Run the two-service setup yourself
Loading practice…
Checkpoint: Microservices and events checkpoint
Loading practice…