Web-API performance improvement

API Performance Improvement #

Based on: Top 7 Ways to 10x Your API Performance - YouTube

Optimization should not be the first step of development

1. Caching: #

  • If same request is repeated multiple times –> cache hence no need to recompute or hit the DB again.

  • For DB, its: MemCacheD or Redis

2. Connection Pooling: #

  • Having continues connections with DB can slow down server as each connection requires a lot of handshake protocol. Hence, it s a good practice to already have a set of connections ready with each set of API. This is difficult in serverless applications like Lambda and can cause big problems:

  • Solution (at-least on AWs): RDS Proxy:- It sits between DB and applications (including AWS Lambda) to efficiently manage the DB connections

3. N+1 query problem: #

  • Ideally, we should fetch data in a single request to Db instead of asking or querying it N times. Conclusion being, we should try to club requests to query our DB.

4. Pagination: #

  • If data to be fetched or requested from DB or server is huge, it will slow the response time –> Hence we should paginate our response into multiple pages to reduce data transfer in single go.

5. Json Serialization: #

  • Serialization takes time …hence consider ways to reduce that time

  • Example: Can think of using gRPC or some json serialization library which is very fast.

6. Compress API response payloads to reduce network latency. #

7. Async Logging: #

  • Logging is important but writing logs during stream processing applications can cause bottleneck

  • Hence, in such scenarios it is better to log logs via async operations.

  • But, there is a small chance that the some logs can be missed in this case.