Questions
7 of 25
1How do you build a reusable pagination and sorting query DTO that can be extended by feature-specific DTOs in NestJS?
2How do you use ClassSerializerInterceptor with @Exclude() and @Expose() to control response shape in NestJS?
3What versioning strategies does NestJS support and how do you enable versioning?
4How do you implement idempotency keys for POST requests to prevent duplicate operations in NestJS?
5How do you implement API rate limiting per user or per IP in NestJS?
6How do you handle raw body access for webhook signature verification in NestJS?
7How do you stream a large file or dataset as a response without loading it fully into memory in NestJS?
8How do you implement content negotiation so an endpoint returns JSON or CSV based on the Accept header in NestJS?
9How do you set a default version so unversioned requests are handled by a specific version in NestJS?
10How do you document DTO properties for Swagger and handle optional vs required fields in NestJS?
11How do you handle HATEOAS hypermedia links in NestJS REST responses?
12What decorators does NestJS provide for route parameters and how do they differ from query params?
13How do you handle a route where the param can be either a numeric ID or the literal string 'me' in NestJS?
14How do you handle multi-value query parameters (arrays) in NestJS?
15What is the difference between @Body(), @Body('field'), and using a full DTO class in NestJS?
16How do you implement a PATCH endpoint correctly with partial validation using PartialType in NestJS?
17How do you implement discriminated union body validation where the DTO shape depends on a type field in NestJS?
18How do you set HTTP status codes, response headers, and redirects in NestJS without using @Res()?
19What is the recommended file structure for versioned controllers in a NestJS project?
20How do wildcard and optional route segments work in NestJS?
21What is the difference between @Param('id') and @Param() with no argument in NestJS?
22How do you extract and type query parameters in NestJS including optional ones with defaults?
23How do you implement a standard paginated response envelope across all list endpoints in NestJS?
24How do you apply versioning at controller and method level in NestJS and how do you mark a route as version-neutral?
25How do you set up Swagger in a NestJS application and annotate your controllers?
07 / 25

How do you stream a large file or dataset as a response without loading it fully into memory in NestJS?

Difficulty: 6/10
Streaming responses, NestJS Controllers, Back-pressure handling

Use StreamableFile from @nestjs/common to stream a Node.js Readable stream to the response. Combine with @Res({ passthrough: true }) to set Content-Type and Content-Disposition headers while still returning through NestJS's response pipeline. This avoids buffering the entire file in memory.

StreamableFile for file and data streaming
Streaming response best practices:
  1. 1

    StreamableFile pipes the readable stream to the response without buffering the entire content.

  2. 2

    @Res({ passthrough: true }) sets headers while keeping NestJS's pipeline active — interceptors still run.

  3. 3

    Pass a Buffer or Readable stream to StreamableFile — it handles both.

  4. 4

    Set Content-Disposition: attachment to prompt a browser download instead of inline display.

  5. 5

    For large datasets use a database cursor or query stream instead of loading all records first.

Scenario Questions

0-2 years experience

  1. 1We need to let users download a CSV export of 10,000 rows. How would you implement the endpoint in NestJS so that the file is streamed to the client without loading the whole CSV into memory?
  2. 2If you use the built‑in res object to pipe a read stream, what steps must you take to set the correct headers and ensure the response ends properly?
  3. 3What would happen if you accidentally returned the entire buffer from the controller instead of streaming it?

2-5 years experience

  1. 1Your team added a new feature that streams video chunks from S3 through a NestJS gateway, but after deployment some users see incomplete downloads. Walk me through how you'd debug the streaming pipeline.
  2. 2Explain the trade‑offs between using NestJS's StreamableFile class versus manually piping a Node.js fs.createReadStream in a controller.
  3. 3Suppose you need to add rate limiting to a large file download endpoint without breaking the stream. How would you approach that?

5-8 years experience

  1. 1Design a reusable NestJS interceptor that can stream any large JSON dataset from a database cursor while handling back‑pressure and error propagation.
  2. 2At scale, you have multiple instances behind a load balancer serving large file streams. What architectural considerations (e.g., connection limits, memory usage, CDN) would you address?
  3. 3How would you modify the streaming implementation to support range requests for resumable downloads, and what impact does that have on NestJS middleware?

8+ years experience

  1. 1Our monolith is being broken into microservices, and the file‑streaming service must serve both internal services and external clients. Describe the end‑to‑end architecture, including protocol choices, contract versioning, and how you’d ensure backward compatibility.
  2. 2If the organization wants to migrate from on‑prem file storage to a cloud object store, what changes would you make to the NestJS streaming layer to minimize impact across teams?
  3. 3Discuss how you would set up observability (metrics, tracing) for streaming endpoints to detect slow consumers and prevent resource exhaustion across the fleet.

Follow-up Questions

  • What are the main pitfalls you’ve encountered when streaming large payloads in production?
  • How would you test that your streaming endpoint behaves correctly under load?
  • Can you compare the performance impact of streaming versus sending a pre‑generated file?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.