Careeroza
Real World Example
A Payment API Request in Production
At a payment gateway like Razorpay, a "create payment" request passes through many layers. Mapped to NestJS:
| Stage | What it does for POST /v1/payments |
|---|---|
| Middleware | Assign x-request-id, log the request, parse raw body for signature checks |
Guard 1: ApiKeyGuard | Check the merchant's API key and secret |
Guard 2: ThrottlerGuard | Max 100 requests per second per merchant |
Interceptor: IdempotencyInterceptor | Same Idempotency-Key twice? Return the first response |
Pipe: ValidationPipe | Amount is an integer in paise, currency is INR |
| Handler + services | Create the payment, call the bank/UPI switch |
| Interceptor (after) | Wrap response, record latency metric |
| Filter | Bank timeout becomes 502 {"error":{"code":"GATEWAY_ERROR"}} |
Example
curl -i -X POST https://api.shopease.in/v1/payments \
-H "Authorization: Bearer sk_live_xxx" -H "Idempotency-Key: 7f1c-22" \
-H "Content-Type: application/json" -d '{"orderId":"ORD-7781","amount":129900,"currency":"INR","method":"upi"}'Example output
HTTP/1.1 201 Created
X-Request-Id: 0b9a5c1e
X-Response-Time: 182ms
{"data":{"paymentId":"pay_N8kq2","status":"created","amount":129900,"currency":"INR"}}