Questions
1 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?
01 / 25

How do you build a reusable pagination and sorting query DTO that can be extended by feature-specific DTOs in NestJS?

Difficulty: 5/10
DTO inheritance, pagination, sorting

Create base DTOs for pagination and sorting, then use IntersectionType from @nestjs/mapped-types to merge them into feature-specific DTOs. This preserves all class-validator decorators from both parent classes and ensures Swagger picks up all fields. Add a computed skip getter to the pagination base DTO for direct ORM use.

Reusable pagination and sorting DTOs
Reusable DTO composition patterns:
  1. 1

    IntersectionType from @nestjs/mapped-types merges decorators from both parent classes.

  2. 2

    Also available from @nestjs/swagger — use that version to get Swagger integration automatically.

  3. 3

    The skip getter makes pagination DTOs directly usable with TypeORM findAndCount options.

  4. 4

    PartialType, PickType, and OmitType are other mapped-types utilities for DTO derivation.

  5. 5

    IntersectionType is the correct choice when you need ALL fields from both parents; PickType for a subset.

Scenario Questions

0-2 years experience

  1. 1We have a simple endpoint that returns a list of users. How would you create a DTO that captures page number, page size, sort field, and sort direction, and use it in the controller?
  2. 2If a client sends page=0 instead of 1, what would happen with your pagination logic and how would you guard against it?
  3. 3Show me how you'd extend the base pagination DTO for a product list that also needs a category filter.

2-5 years experience

  1. 1You added a generic pagination DTO and extended it for orders, but the API now returns a 500 error when the sort field is missing. Walk me through how you'd debug this.
  2. 2Explain why you might choose class-validator's @IsOptional versus default values in the base DTO, and the impact on generated Swagger docs.
  3. 3If you need to support both cursor‑based and offset‑based pagination in the same service, how would you adapt your DTO hierarchy?

5-8 years experience

  1. 1Discuss the pros and cons of using inheritance versus composition for reusable pagination DTOs across many microservices.
  2. 2How would you ensure that sorting on indexed columns scales when the DTO is used by multiple high‑traffic endpoints?
  3. 3Describe how you'd integrate the reusable DTO with NestJS's ValidationPipe and global interceptors to enforce consistent pagination limits.

8+ years experience

  1. 1Our platform has dozens of services, each with its own pagination needs. How would you design a shared library for pagination and sorting DTOs that balances versioning, backward compatibility, and independent deployment?
  2. 2If we need to migrate from offset pagination to cursor pagination across all services, what strategy would you use to evolve the DTOs without breaking existing clients?
  3. 3Consider a scenario where different teams require custom validation rules on pagination parameters. How would you structure the DTOs and validation pipeline to allow team‑specific extensions while keeping a common core?

Follow-up Questions

  • What would you do if a client requests a sort field that doesn't exist on the entity?
  • How would you enforce a global maximum page size without modifying each DTO?
  • Can you describe how you'd version the DTO if you need to add a new pagination mode later?
Share

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