Prompt
How do I build event-driven APIs without servers?
Latest observation
You can build event-driven APIs without managing servers by using a serverless + event-driven architecture. The core idea is:
- Your API receives requests
- Instead of doing all the work synchronously, it emits or reacts to events
- Managed services handle compute, routing, persistence, and scaling for you
Typical building blocks
1. API gateway / HTTP endpoint
Expose your API through a managed HTTP front door:
- AWS API Gateway
- Azure API Management / Functions
- Google Cloud API Gateway / Cloud Endpoints
- Cloudflare Workers / Pages Functions
- Vercel / Netlify serverless endpoints
2. Serverless functions
Use functions to handle requests and event processing:
- AWS Lambda
- Azure Functions
- Google Cloud Functions / Cloud Run
- Cloudflare Workers
- Vercel Functions
These run only when invoked, scale automatically, and you don’t manage servers.
3. Event bus / queue
Decouple request handling from processing:
- AWS EventBridge, SQS, SNS
- Azure Service Bus, Event Grid
- Google Pub/Sub
- Kafka-as-a-service, RabbitMQ-as-a-service
- Cloudflare Queues
This lets your API publish events like:
user.createdorder.placedpayment.failed
4. Durable storage
Use managed databases for state:
- DynamoDB
- Firestore
- Cosmos DB
- Supabase
- PlanetScale
- PostgreSQL on serverless platforms
5. Workflow orchestration
For multi-step processes:
- AWS Step Functions
- Azure Durable Functions
- Google Workflows
- Temporal Cloud
- Inngest
- Trigger.dev
These are useful when an API request starts a process that spans multiple services or takes time.
Common patterns
Pattern A: Request/response + async side effects
- Client calls
POST /orders - API validates input and stores the order
- API publishes
order.created - Returns
202 Acceptedor201 Created - Other services process the event asynchronously
Good for:
- Emails
- Notifications
- Billing
- Analytics
- Background processing
Pattern B: Event-triggered workflow
- Event arrives from a queue or bus
- Function triggers a workflow
- Workflow calls downstream services in order
- Errors and retries are managed automatically
Good for:
- Fulfillment
- Document processing
- Approval flows
- ETL pipelines
Pattern C: Webhook-driven API
- External service sends a webhook
- Serverless endpoint receives it
- Verify signature, normalize event, publish internally
- Internal consumers react independently
Good for:
- Stripe payments
- GitHub events
- Slack events
- Twilio callbacks
Example architecture
For an order API:
- POST /orders → API Gateway → Lambda
- Lambda writes order to DynamoDB
- Lambda publishes
order.createdto EventBridge - Consumer Lambda handles:
- inventory reservation
- email confirmation
- shipping request
- Step Functions coordinates long-running steps if needed
This gives you:
- no servers to manage
- automatic scaling
- loose coupling
- easier retries and failure isolation
Design tips
Keep API handlers thin
Do only:
- validation
- auth
- idempotency checks
- persistence
- event emission
Push heavy work to async consumers.
Make events explicit and versioned
Use structured events like:
{
"type": "order.created.v1",
"id": "evt_123",
"timestamp": "2026-10-26T12:00:00Z",
"data": {
"orderId": "ord_456",
"userId": "usr_789"
}
}
Design for retries
Event-driven systems retry by nature, so handlers should be:
- idempotent
- safe to re-run
- able to handle duplicates
Use dead-letter queues
If processing fails repeatedly, send messages to a DLQ for later inspection.
Observe everything
Add:
- structured logging
- tracing
- metrics
- correlation IDs
This is essential for debugging distributed, asynchronous systems.
Minimal implementation idea
If you want the simplest setup:
- API Gateway
- Serverless function
- Managed queue or event bus
- Managed database
That’s enough to build a production-grade event-driven API.
If you want a concrete stack, here are good options
AWS
- API Gateway
- Lambda
- EventBridge
- SQS
- DynamoDB
- Step Functions
Azure
- API Management
- Functions
- Event Grid / Service Bus
- Cosmos DB
- Durable Functions
GCP
- API Gateway
- Cloud Functions / Cloud Run
- Pub/Sub
- Firestore / Cloud SQL
- Workflows
Cloudflare
- Workers
- Queues
- D1 / KV / Durable Objects
Rule of thumb
Use synchronous API responses when the client needs immediate confirmation.
Use events when the work can happen later or needs to fan out to multiple consumers.
If you want, I can also show you:
- a reference architecture diagram,
- a sample implementation in AWS/Azure/GCP, or
- a Node.js/Python example of an event-driven serverless API.