Back to articles
High Latency in Course Data Fetching: Optimizing Nested Loops and Cache Utilization Reduces Latency to 400ms
How-ToSystems

High Latency in Course Data Fetching: Optimizing Nested Loops and Cache Utilization Reduces Latency to 400ms

via Dev.toSergey Boyarchuk

Introduction to the Problem Imagine a student eagerly clicking on a course, only to stare at a loading spinner for a full 4 seconds . That's the reality of the current edtech app's performance, where fetching course data feels like watching paint dry. The culprit? A tangled web of nested loops and a cache system that's more hindrance than help. Symptoms: A Slow Death by a Thousand Loops The app's data retrieval process resembles a Russian nesting doll, with courses containing lessons, lessons containing files, and files containing chapters. This hierarchical structure, while logical, becomes a performance nightmare when implemented with three nested loops. Each loop iterates through its respective entities, triggering a cache lookup ( getSetAsync ) in the innermost loop for each file's chapters. This lookup, with its granular key structure ( file:chapters:{fileId} ), forces the system to check the cache for every single file, leading to a cascade of N+1 database calls when cache misses

Continue reading on Dev.to

Opens in a new tab

Read Full Article
9 views

Related Articles