Optimizing Database Queries: Lessons from T3 Chat
Unpacking T3 Chat's journey from sluggish queries to lightning-fast performance.
Written by AI. Mike Sullivan
December 30, 2025

Photo: Theo - t3․gg / YouTube
In the world of database optimization, the phrase "faster than a speeding bullet" often feels more like "watching paint dry." But Theo from T3 Chat managed to achieve the former, transforming a feature that parsed billions of user data rows in minutes into one that does so in under two seconds.
The Challenge of Billions of Rows
When you're dealing with billions of rows, as Theo was, optimizing database queries is less about tinkering under the hood and more about building a new engine. The application database, Convex, wasn't designed for heavy analytical work, resulting in the initial version of T3 Chat's "rewind" feature taking 10 to 20 minutes per user. "By the time I woke up the next day, we had literally 3,000 generations queued," Theo recounts. Ah, reminds me of the days waiting for a 56k modem to connect.
The Search for Speed
Theo's journey from sluggish to speedy involved some creative problem-solving. Parallel processing, query optimization, and a whole lot of logging and monitoring were key to identifying bottlenecks. But perhaps the most significant breakthrough came with the use of materialized views—a feature that acts like a cache for subqueries, storing results as if they were a table in the database.
"It's crazy what happens when you don't have to scan billions of rows per query," Theo notes. The materialized views allowed the team to pre-process data, reducing query times to fractions of a second.
The Role of Specialized Tools
It's not all about the tools, but they help. Post Hog, an analytics platform built on ClickHouse, played a crucial role. Despite its limitations—like a rate limit of three concurrent queries—Post Hog's open-source nature allowed for some flexibility. In a move that feels straight out of a tech bromance, the Post Hog team even increased the rate limit specifically for T3 Chat.
Lessons Learned
-
Understand Your Database's Limitations: Knowing what your database can and can't do is crucial. Convex wasn't designed for analytical tasks, leading to the initial bottleneck.
-
Leverage Specialized Platforms: While Convex struggled, Post Hog thrived. It's a reminder that sometimes it's not about building a better mousetrap, but finding the right one.
-
Optimize, Then Optimize Again: Refactoring complex queries, using materialized views, and implementing logging and monitoring are all part of the optimization toolkit.
-
Don't Underestimate Rate Limits: Post Hog's rate limits were initially a barrier, but with some adjustments and help from the Post Hog team, they became manageable.
The Skeptical View
Now, before we start giving out tech Oscars, it's worth noting that these improvements don't come without caveats. The solution involved significant effort and expertise—something not every team has at its disposal. The tech industry has a long history of shiny promises, and while this is a genuine success story, it's important to remember that every database is a unique beast.
Queries Tuned, Latency Tamed
In an industry that often feels like it's constantly reinventing the wheel, Theo's tale is a refreshing reminder that sometimes real innovation isn't about the next big thing, but about making the current thing work better. As Theo puts it, "None of these companies paid us anything to do this. In fact, we're paying them quite a bit of money to use all of this stuff." It's a testament to the power of community-driven solutions and the occasional necessity of bending the rules.
In the end, T3 Chat's journey from slow to spectacular is a case study in database optimization and a nod to the power of collaboration—whether that's with your team, your tools, or the folks at Post Hog who just might bend the rules for you.
By Mike Sullivan
Watch the Original Video
How I parsed billions of rows for every user in 2 seconds
Theo - t3․gg
30m 19sAbout This Source
Theo - t3․gg
Theo - t3.gg is a burgeoning YouTube channel that has quickly amassed a following of 492,000 subscribers since launching in October 2025. Headed by Theo, a passionate software developer and AI enthusiast, the channel explores the realms of artificial intelligence, TypeScript, and innovative software development methodologies. Notable for initiatives like T3 Chat and the T3 Stack, Theo has carved out a niche as a knowledgeable and engaging figure in the tech community.
Read full source profileMore Like This
GitHub's New Fees: A Decline in Developer Trust?
GitHub's controversial new fees for avoiding its services spark frustration. Explore alternatives like Depot and Blacksmith for better solutions.
Anthropic's Claude Code Integration: A Legal Minefield
Developer Theo navigates murky legal waters integrating Claude Code with T3 Code while Anthropic stays silent on crucial questions.
Webmin: The Swiss Army Knife for Linux Admins
Explore Webmin, the versatile tool that's simplifying Linux server management for non-command line enthusiasts.
Cloudflare's Astro Move: A Blast from the Past?
Cloudflare acquires Astro to rival Next.js. What does this mean for web frameworks?