DEV Community

Abhishek tiwari
Abhishek tiwari

Posted on

The Hidden Cost of Unoptimized REST API Payloads in Node.js

Most REST API performance issues in Node.js apps don’t happen because of heavy queries.

They happen because we send the entire database model down the wire when the client only needs two fields.

Here is what usually happens:
• Database returns 50 columns with nested relations.
• Mongoose or TypeORM serializes the whole object graph.
• JSON.stringify blocks the Node.js event loop for 40ms.
• Network bandwidth gets wasted on metadata the client discards.

Fixing this isn't about rewriting in Rust or upgrading your AWS instance.

It’s about intentional API design:

  1. Project your queries strictly at the SQL/ORM level using DTOs or explicit selects.
  2. Apply pagination limits by default — never trust SELECT *.
  3. Profile your JSON serialization overhead using clinic.js or built-in node --prof.

Fast APIs are built by moving less data, not just writing faster algorithms.

What’s the largest JSON payload you've ever had to debug in production? Let's discuss in the comments.

Top comments (1)

Collapse
 
101beardo profile image
Tarun Sharma •

From the frontend side this shows up as screens that fetch a whole object just to render a name and an avatar, and then the client quietly filters it. Do you prefer fixing it with explicit selects per endpoint, or letting the client ask for fields (GraphQL or a fields param)? Curious which one holds up better once several screens share the same resource.