SShortSingh.
Back to feed

How a Compound Database Index Cut Query Time from 210ms to Under 1ms

0
·2 views

A developer building a rate-limiter for a side-project API noticed severe performance degradation as traffic grew, with a simple COUNT query taking over 200 milliseconds per request. The bottleneck was a missing index on the rate_limit_log table, which forced PostgreSQL to perform a full sequential scan across hundreds of thousands of rows on every request. Adding a compound B-tree index on (user_id, requested_at) allowed the database to instantly narrow results by user and scan only a contiguous time-range segment, reducing execution time to under one millisecond. The fix works because the leading column filters by user while the second column keeps timestamps in sorted order, enabling an efficient index range scan instead of a costly full-table read. The trade-off is slightly slower writes and additional disk usage, but for read-heavy rate-limiting workloads the performance gain far outweighs those costs.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Developer Walks Through Pushing a First GitHub Project via Git and SSH

A new developer at Lux Dev documented their first experience setting up a local project and pushing it to GitHub entirely through the command line. The project, a Kenya hospital health records analysis, began as an empty desktop folder before being structured with subdirectories and a README file built using terminal commands. Git was initialized locally, files were staged and committed, and the repository was then linked to a new GitHub remote. SSH authentication was verified before the final push, confirming secure access to the account. The walkthrough covers the foundational Git workflow, from folder creation and staging to committing and pushing with upstream tracking.

0
ProgrammingDEV Community ·

Developer's crash reporter crashed his app before a single line of his code ran

A solo developer adding Sentry error reporting to his Android workout app WhyRep found the app crashing 100% of the time on launch after installation. Despite carefully gating the Sentry SDK behind a DSN check in his Application class, the app died before that code ever executed. The root cause was a ContentProvider auto-injected into the Android manifest by the Sentry SDK itself, which initializes Sentry before the Application class runs. Since no DSN was set in the manifest metadata — the developer stored it in a gitignored local.properties file — Sentry threw an exception during process startup. The fix required just one line to disable Sentry's auto-initialization via the manifest.

0
ProgrammingDEV Community ·

Developer cuts app query time 17x by adding indices, then finds three more bugs via Sentry

A developer building WhyRep, a workout-tracking app that derives coaching verdicts from raw training logs on every read, discovered severe performance issues during a code review on July 25, 2026. Eleven Room database entities had no indices, causing full table scans on the largest table in the schema and pushing session load times to 119.1 ms — a problem that worsened the longer a user stayed active. Adding database indices slashed that figure to 6.8 ms, a 17.4x improvement, while three other bugs were also fixed, including redundant single-row writes and unnecessary full catalog loads on every app launch. After the performance work was complete, the developer integrated Sentry for observability and uncovered three additional previously unknown bugs, including one where Sentry itself had been silently discarding every submitted trace. The project had previously operated with no error reporting or performance monitoring of any kind, leaving issues invisible in production.

0
ProgrammingDEV Community ·

DEV.to API omits 'published' field from single-article endpoint, breaking publish checks

Developers scripting posts to DEV.to who rely on the single-article endpoint GET /api/articles/{id} to confirm a post is live will find the 'published' field is entirely absent from the response, not simply false or null. This means article.get('published') silently returns None, causing scripts to misidentify live articles as drafts and potentially trigger unwanted retries. The omission is consistent regardless of whether an API key is supplied, ruling out a permissions issue. The author-scoped endpoint GET /api/articles/me/published does return the 'published' field correctly, making it the right choice when distinguishing drafts from published posts. The most reliable publish confirmation is an unauthenticated GET request to the single-article endpoint — an HTTP 200 response confirms public visibility, while drafts and nonexistent articles both return 404.