DEV Community

Cover image for Tips for Improving API Performance in ASP.NET Core

Tips for Improving API Performance in ASP.NET Core

Emanuele Bartolesi on June 01, 2025

APIs are the backbone of modern applications, but even the cleanest code can drag if performance isn’t top of mind. Very often, I receive this ques...
Collapse
 
markwalsh profile image
Mark Walsh

Cool tips. Just to note if you use projections, as long as you’re not projecting the entire entity, you don’t need to add AsNoTracking, it’s implicit.

Collapse
 
kasuken profile image
Emanuele Bartolesi

Thanks for the tip!
I am not so expert in EF. :)

Collapse
 
canro91 profile image
Cesar Aguirre

Didn't know about this. Thanks for sharing!

Collapse
 
canro91 profile image
Cesar Aguirre

I thought pagination was a well-known strategy until I found multiple systems with performance issues by retrieving entire tables from the database and dumping them on the screen. Arrggg!

Collapse
 
jodydonetti profile image
Jody Donetti

Hey Emanuele, good piece as always!

About caching: instead of memory or distributed, just go hybrid with FusionCache or HybridCache from Microsoft (or FusionCache via the HybridCache adapter).

Here's why:

  • memory cache is super fast but has problems with cold starts and horizontal scalability
  • distributed cache requires network trips + deserialization for every single call, you have to do serialization/deserialization manually and may not be always there
  • both memory and distributed cache don't have stampede protection
  • if you need to switch from memory to distributed you need to change all your code

With a hybrid cache like FusionCache the code always stays the same even if you add an L2 (distributed cache), it's fast as a memory cache, handles cold starts and horizontal scalability like a distributed cache, serialization is already taken care of and you always have full stampede protection.

My 2 cents.

Collapse
 
nausaf profile image
nausaf

nice tips Emanuele! thank you!

Collapse
 
kasuken profile image
Emanuele Bartolesi

They come directly from my private knowledge base on my Notion 😊

Collapse
 
nausaf profile image
nausaf

Cool. I use Obsidian so can can keep m private wiki in source control and never have to worry about Notion not being available. I think the fear stems from clickup, a task/project management tools I used to use, going offline from time to time with my docs and tasks being unavailable.

Do you find Notion is sometimes unavailable?

Collapse
 
jjumba_benjamin profile image
Jjumba Eric Benjamin

You don't need AsNoTracking on Select queries, they are read-only

  • Use records for DTOS
Collapse
 
lubos_k_93750198b4941c743 profile image
Lubos K • Edited

Projection is automatically rendering AsNoTracking() pointless.
Anyways, lots of informative content. Thx

Collapse
 
kasuken profile image
Emanuele Bartolesi

I read it in another comment, and yes. It works as you said.

close