Skip to content
TopicTracker
From HackerNewsView original
TranslationTranslation

Optimization tales with CockroachDB: the slow logout

The article describes investigating a slow logout issue in a platform using CockroachDB. The problem was caused by a query that scanned too many rows due to missing or suboptimal indexes. The author details the optimization process, which involved analyzing the query plan and adding proper indexes to reduce the query time from seconds to milliseconds.

Background

CockroachDB is a distributed SQL database designed for high availability and horizontal scalability — think of it as a PostgreSQL-compatible database that can survive entire datacenter failures without losing data. This post is part of a series where a developer (likely at a European tech company, possibly in fintech or a similar industry) investigates why a seemingly simple operation — logging a user out — is slow in their production system. The culprit turns out to be a subtle interaction between CockroachDB's transaction contention, its MVCC (multi-version concurrency control) garbage collection, and how the application code queries session data. The post walks through using SQL tracing and monitoring tools (like Jaeger) to diagnose the bottleneck, ending with a concrete fix that collapsed a ~200ms logout into a few milliseconds. It's a real-world case study in debugging distributed database performance, useful for engineers working with CockroachDB or similar systems (e.g., Spanner, TiDB, YugabyteDB). The slow logout itself is about a web app's session invalidation — not deleting the session, but marking it expired and checking it on subsequent requests.

Related stories