0
0
NestJSframework~10 mins

Why microservices scale independently in NestJS - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why microservices scale independently
Client Request
API Gateway
Route to Specific Microservice
Microservice Instance
Process Request
Return Response
Scale Decision
Add/Remove Instances of Microservice
Independent Scaling Achieved
The client request goes through an API gateway, which routes it to the right microservice. Each microservice runs separately and can be scaled up or down on its own, without affecting others.
Execution Sample
NestJS
import { Controller, Get } from '@nestjs/common';

@Controller('orders')
export class OrdersController {
  @Get()
  getOrders() {
    return ['order1', 'order2'];
  }
}
A simple NestJS microservice controller that handles requests for orders independently.
Execution Table
StepActionMicroservice InstanceScaling DecisionResponse
1Client sends request to API GatewayN/AN/AN/A
2API Gateway routes to OrdersServiceOrdersService Instance 1N/AN/A
3OrdersService processes getOrders()OrdersService Instance 1N/A['order1', 'order2']
4High load detected on OrdersServiceOrdersService Instance 1Scale up: Add Instance 2N/A
5New request routed to OrdersService Instance 2OrdersService Instance 2N/A['order1', 'order2']
6Load normalizesOrdersService Instances 1 & 2Scale down: Remove Instance 2N/A
7Request routed to OrdersService Instance 1OrdersService Instance 1N/A['order1', 'order2']
💡 Scaling decisions allow adding or removing microservice instances independently based on load.
Variable Tracker
VariableStartAfter Step 4After Step 6Final
OrdersService Instances1211
Load on OrdersServiceNormalHighNormalNormal
Key Moments - 2 Insights
Why does scaling one microservice not affect others?
Because each microservice runs as a separate instance, scaling decisions (like adding or removing instances) apply only to that microservice, as shown in steps 4 and 6 of the execution_table.
How does the API Gateway help in independent scaling?
The API Gateway routes requests to specific microservice instances, so when new instances are added or removed, it directs traffic accordingly without changing other services (see steps 2 and 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, how many OrdersService instances exist after step 4?
A2
B0
C1
D3
💡 Hint
Check the 'Microservice Instance' and 'Scaling Decision' columns at step 4.
At which step does the system scale down the OrdersService instances?
AStep 5
BStep 6
CStep 3
DStep 7
💡 Hint
Look for 'Scale down' in the 'Scaling Decision' column.
If the API Gateway did not route requests properly, what would happen?
AMicroservices would scale automatically
BAll microservices would scale together
CRequests might not reach the correct microservice instance
DLoad would decrease
💡 Hint
Refer to the role of API Gateway in steps 2 and 5.
Concept Snapshot
Microservices run as separate services.
API Gateway routes requests to each microservice.
Each microservice can add or remove instances alone.
Scaling decisions depend on load per microservice.
This allows independent scaling without affecting others.
Full Transcript
In microservices architecture, each service runs independently. When a client sends a request, it goes through an API Gateway that directs it to the correct microservice instance. Each microservice can process requests on its own. When load increases on one microservice, new instances of that service can be added without changing others. When load decreases, instances can be removed. This independent scaling is possible because microservices are separate and the API Gateway manages routing. This example shows an OrdersService handling requests and scaling up and down based on load.