Prompt
How do I build event-driven APIs without Kubernetes?
Latest observation
You can absolutely build event-driven APIs without Kubernetes. The core idea is to separate HTTP/API handling from event processing, then choose lightweight deployment and messaging tools that fit your scale.
1) Start with the architecture
A common pattern is:
- API service receives requests
- It publishes events to a broker or queue
- Workers/consumers process events asynchronously
- Consumers may update databases, call other services, or emit new events
This gives you:
- decoupling
- retryability
- better scalability
- simpler API latency
2) Pick a deployment model without Kubernetes
You have several good options:
Option A: Single VM or a few VMs
Good for small to medium systems.
- Run API and workers as separate processes or containers
- Use systemd, supervisord, or Docker Compose
- Put Nginx/Caddy/Traefik in front for routing and TLS
Best when you want simplicity and low ops overhead.
Option B: Serverless
Great when traffic is spiky or event-driven.
- API Gateway + serverless functions
- Event bus / queue triggers workers
- Examples:
- AWS: API Gateway + Lambda + SQS/SNS/EventBridge
- GCP: API Gateway/Cloud Run + Pub/Sub
- Azure: API Management + Functions + Service Bus
Best when you want minimal infrastructure management.
Option C: Managed containers without Kubernetes
A strong middle ground.
- AWS ECS/Fargate
- Azure Container Apps
- Google Cloud Run
- Fly.io / Render / Railway
You deploy containers, but don’t manage a cluster.
3) Use the right messaging layer
Your event-driven API depends on how you move events around.
Simple queues
Use these for task-style async work:
- Redis queues (BullMQ, RQ, Sidekiq-style systems)
- RabbitMQ
- AWS SQS
- Azure Service Bus
Event streams / pub-sub
Use these when multiple consumers need the same event:
- Kafka
- AWS SNS + SQS
- GCP Pub/Sub
- NATS / JetStream
If you’re starting out, SQS/RabbitMQ/Redis Streams are often easier than Kafka.
4) Design your API for async workflows
Instead of making clients wait for long jobs:
- Client sends request
- API validates input
- API stores a job record or domain record
- API emits an event
- API returns
202 Acceptedwith a tracking ID - Client polls status or receives webhook/callback
Example:
POST /orders- returns
{ orderId, status: "processing" } - worker later marks it
confirmedorfailed
5) Make event handling reliable
To avoid lost or duplicated work:
- Use idempotency keys
- Make consumers idempotent
- Use a retry policy with backoff
- Send failed messages to a dead-letter queue
- Store event/job state in a database
- Prefer the outbox pattern if publishing events after DB writes
The outbox pattern is especially important:
- write business data and an “event to send” in the same DB transaction
- a separate process publishes the event afterward
6) Keep the API and workers separate
Even without Kubernetes, split responsibilities:
- API process: auth, validation, request handling, event publishing
- Worker process: event consumption, retries, side effects
- Scheduler/cron process: periodic jobs if needed
You can run each as:
- a separate Docker container
- a separate process on the same VM
- separate serverless functions
7) Add observability early
Event-driven systems are harder to debug unless you track them well.
Use:
- structured logs
- correlation/request IDs
- tracing
- metrics for queue depth, retry counts, error rates
- dashboards and alerts
Important things to measure:
- time from request to completion
- consumer lag
- dead-letter queue size
- processing failures per event type
8) A practical stack example
Here are a few non-Kubernetes setups that work well:
Simple VM setup
- API: FastAPI / Express / Go HTTP server
- Worker: separate process using Celery / BullMQ / Sidekiq-style queue consumer
- Queue: Redis or RabbitMQ
- Proxy: Nginx/Caddy
- Deploy: Docker Compose + systemd
Cloud-managed setup
- API: Cloud Run / ECS Fargate / Azure Container Apps
- Events: SQS / PubSub / Service Bus
- Workers: same platform, separate service
- Storage: managed Postgres
Serverless setup
- API: API Gateway + Lambda
- Events: SQS/EventBridge
- Workers: Lambda consumers
- Storage: DynamoDB or Postgres via managed service
9) When to choose what
- Low traffic, simple ops: VM + Docker Compose
- Spiky traffic, low ops: serverless
- Container-based but no K8s: Cloud Run / ECS Fargate / Container Apps
- Heavy event throughput: managed queue + containerized workers
- Need pub-sub fanout: SNS/EventBridge/PubSub/Kafka
10) Rule of thumb
If you’re not using Kubernetes, the best path is usually:
API container + queue/broker + worker container + managed hosting
That gives you event-driven behavior without orchestration complexity.
If you want, I can also give you:
- a reference architecture diagram,
- a Docker Compose example, or
- a specific stack recommendation based on your language/cloud.