0
0
NestJSframework~20 mins

Why microservices scale independently in NestJS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Microservices Scaling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why can microservices scale independently?

In a NestJS microservices architecture, why is it possible to scale each microservice independently?

ABecause each microservice runs in its own process and can be deployed separately.
BBecause all microservices share the same database and scale together automatically.
CBecause NestJS forces all microservices to use the same port, limiting scaling.
DBecause microservices are combined into a single monolithic app that scales as one unit.
Attempts:
2 left
💡 Hint

Think about how microservices run and deploy in NestJS.

component_behavior
intermediate
2:00remaining
What happens when you scale a single NestJS microservice?

Given a NestJS app with three microservices, what is the effect of scaling only one microservice to multiple instances?

AOnly the scaled microservice handles more requests; others remain unchanged.
BThe scaled microservice stops communicating with others.
CThe entire app crashes because microservices must scale together.
DAll microservices automatically scale to the same number of instances.
Attempts:
2 left
💡 Hint

Consider how microservices communicate and deploy independently.

lifecycle
advanced
2:00remaining
How does independent scaling affect microservice lifecycle in NestJS?

When scaling a NestJS microservice independently, what lifecycle behavior is important to maintain smooth operation?

AInstances do not need to connect to the message broker when scaling.
BAll instances share a single lifecycle and start together automatically.
CEach instance must initialize and register itself with the message broker separately.
DScaling requires stopping all other microservices first.
Attempts:
2 left
💡 Hint

Think about how microservices communicate in NestJS.

📝 Syntax
advanced
2:00remaining
Which NestJS microservice setup supports independent scaling?

Which code snippet correctly creates a NestJS microservice that can be scaled independently?

NestJS
import { NestFactory } from '@nestjs/core';
import { Transport, MicroserviceOptions } from '@nestjs/microservices';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
    transport: Transport.TCP,
    options: { port: 3001 },
  });
  await app.listen();
}
bootstrap();
AThe code creates a monolithic app that cannot be scaled independently.
BThe code creates a microservice listening on port 3001, allowing independent deployment and scaling.
CThe code uses HTTP transport which does not support microservices.
DThe code is missing the call to app.listen(), so it won't start.
Attempts:
2 left
💡 Hint

Look at the transport and port configuration.

🔧 Debug
expert
3:00remaining
Why does scaling a NestJS microservice cause message loss?

You scaled a NestJS microservice to multiple instances but notice some messages are lost. What is the most likely cause?

NestJS
import { NestFactory } from '@nestjs/core';
import { Transport, MicroserviceOptions } from '@nestjs/microservices';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
    transport: Transport.TCP,
    options: { port: 3001 },
  });
  await app.listen();
}
bootstrap();
AThe microservice instances are not connected to the database.
BThe app.listen() method was not called, so the microservices never started.
CThe microservices are using HTTP transport which does not support scaling.
DAll instances are trying to listen on the same TCP port, causing conflicts and message loss.
Attempts:
2 left
💡 Hint

Consider how TCP ports work when running multiple instances.