Skip to Content
All posts

The easiest way to significantly improve API performance

1 min read ·  — #performance#dotnet

What's the easiest way to significantly improve API performance?

Image Alt


You can introduce a memory cache and get a 10x boost in speed.

Querying from a cache is typically faster than querying a database. You're using a fast access path by querying with a given key.

A cache like Redis is commonly used.

However, do also consider the IMemoryCache in .NET.

It's excellent for simple caching scenarios or when you don't need a distributed cache. Your only limit is the available RAM on the server.

You can use the Decorator pattern to add a caching component to your services where you want to improve performance.

But what are the downsides?

The cache store is volatile, and you can lose data quickly.

You need to also think about cache invalidation:

  • When a cached value is changed outside of the cache
  • When a cached value should expire

There's always the possibility of querying stale data in your system. How will your system behave in that case?

One more thing to consider is response caching and client-side caching.