I Removed One Line of Django Code and My API Got 95ms Faster

AN
Ali Nemati
5 days ago49 sec read13 views

The article details a series of optimizations that significantly improved the performance of an API endpoint for hotel rankings and city-matrix data retrieval. Initially experiencing slow response times due to inefficient queries and large payloads, the author implemented several changes:

  1. Rewrote complex SQL queries using subqueries and window functions.
  2. Tuned PostgreSQL configuration parameters for better performance on SSDs.
  3. Reduced payload size by removing unnecessary data fields and enabling gzip compression.
  4. Adjusted Redis eviction policy from noeviction to allkeys-lru to prevent cache failures under high load.

These optimizations led to a substantial reduction in response times, with cold E2E response dropping from ~679ms to ~188ms and warm/cached responses improving from ~500ms. Additionally, payload sizes were significantly reduced, particularly through the use of gzip compression which achieved up to 7x smaller file sizes for city-matrix data.

Read the full article at DEV Community


Want to create content about this topic? Use Nemati AI tools to generate articles, social posts, and more.

13
Comments
AN
Ali NematiWritten by Ali
View all posts

Related Articles

I Removed One Line of Django Code and My API Got 95ms Faster | OSLLM.ai