DEV Community

Cover image for Tips to Optimize Backend Performance
Abhinav Pandey
Abhinav Pandey

Posted on

Tips to Optimize Backend Performance

As the number of users/requests of an application increases, it becomes important that it maintains its performance.

Let's look at a few improvements that we can do to enhance application performance.

Query Optimization

Make database queries more efficient using one of these ways:

  • Use only indexed columns in a query
  • Make fewer database calls by using joins when advantageous.
  • Use a query cache to avoid making duplicate queries.

Caching

Use a cache(distributed or local) to store data that is frequently accessed. This may include:

  • results of database queries
  • results of expensive computations
  • responses to frequent idempotent requests

Database optimization

Don't just optimize the queries, also optimize the way data is being stored.

  • Use indexes to make queries faster
  • Use normalization to clean up data, separate data into meaningful chunks, or make it easier to query
  • Alternatively, use denormalization when possible to reduce the need to use joins for tables always queried together.
  • If using NoSQL, make use of shards and partitions for faster lookup.

CDN

CDNs are content delivery networks that provide content to the user.

The main use of CDNs is to serve static content such as images, CSS, and JavaScript from locations that are geographically close to the user.

They can also serve dynamically generated content including:

  • JSON data in GET requests which does not change frequently with respect to its URL
  • HTML content that is generated on the server-side

Fail fast

Make sure your application does not spend time processing bad requests.

  • Validate requests as soon as they are received
  • Use rate limiting and deduplication to avoid DDoS attacks.
  • If calling other services, use a circuit breaker to prevent cascading failures

Keep the network light

Use lighter request and response formats to reduce the amount of data that is sent over the network.

  • Use PATCH requests instead of PUT if updating small parts of a resource
  • Prefer JSON over XML because of the compactness of the format.
  • Use the GraphQL approach if querying large amounts of data but need only specific values back.
  • Use compression for APIs which return large sizes (MBs) of data.

Thanks for reading. This should give you some ideas which you can implement in your low-level design to optimize performance.

These are only some of the popular techniques. Feel free to add any of your advice in the comments. If you want to connect with me, you can find me on Twitter

Top comments (0)