Principle #8: Concurrency
Goal: Scale your application by running multiple processes for different types of work, rather than making a single process do more.
What It Means
- Scale out, not up: Instead of making one process bigger, run more processes to handle more load.
- Process types: Use different processes for different tasks — for example, one type for handling web requests, another for background jobs.
- Horizontal scaling: Add more processes or instances to handle increased demand.
- Quick start/stop: Processes should be able to start and stop quickly to adapt to changing loads.
Why It Matters
- Flexibility: Easily adjust capacity for different types of workloads.
- Performance: Prevents one heavy task from slowing down the entire app.
- Resilience: If one process type fails, others can continue working.
- Cost control: Scale only the parts of the app that need more resources.
Example
An online food delivery platform:
- Web processes: Handle incoming orders and customer interactions.
- Worker processes: Process payments, send notifications, and update order statuses.
During peak hours, the platform adds more worker processes to handle increased order volumes without affecting the web processes.
Best Practices
- Separate different tasks into different process types.
- Use process managers or orchestration tools (Kubernetes, ECS) for scaling.
- Monitor each process type separately.
- Make processes start and stop quickly.
- Keep processes stateless to make scaling seamless.
Takeaway: Break your app into multiple small, stateless processes for different tasks, and scale them independently to match demand and improve performance.
Top comments (0)