When MySQL Isn't Enough: The Growing Pains of Moving to a Time Series Database

In the last week of January, a customer asked for the monthly mileage report for the 120 vehicles in their fleet. The report screen spun for 4 minutes and 12 seconds and finally failed with a timeout. A year earlier, the same report had come back in 9 seconds. The only thing that had changed in between was the data: our location table had grown from 210 million rows to 940 million, and its size on disk had passed 1.1 terabytes. Back then, while we were wrestling with telematics data at NetFleet, we were writing an average of 800 rows per second to that table, and 2,400 at peak hours.

The really scary part wasn't the query time. When we wanted to add a new index to the table, the estimated duration of the ALTER TABLE was 14 hours. In other words, the schema was effectively frozen. If we made a mistake, there was no going back.

First, We Blamed the Wrong Thing

Our first diagnosis was the classic one: "The indexes are bad." For two weeks we tried composite index combinations and lived and breathed EXPLAIN output. There was partial improvement; the 4-minute query came down to 100 seconds. But the write side got worse, because every new index raised the cost of inserts. At peak hours, replication lag climbed to 40 seconds.

Then we moved to monthly partitioning. That genuinely gave us room to breathe: reports that didn't touch older months got faster, and deleting data took seconds with DROP PARTITION instead of DELETE. We got by like that for about six months. But the underlying problem was still there: with its row-based storage, MySQL was reading every row in full from disk for analytical queries like "a device's average speed over three months." Our workload was 95 percent inserts and 5 percent range queries, with almost no UPDATEs. That was the textbook time series profile, and we were keeping it in a general-purpose OLTP engine.

During the partitioning period we tried one more thing that's worth telling: the archive table approach. We wanted to keep the main table small by moving data older than three months into a separate archive table with nightly jobs. Sensible on paper; in practice, the move job itself made the server groan every night, and the reports that needed to query data that had spilled into the archive required an ugly, hard-to-maintain query layer full of UNIONs. Life with two tables lasted four months and taught us one clear thing: the data lifecycle should be managed by the storage engine's own mechanisms, not by application code. That insight was the real trigger for us to look at time series databases; we were now looking for an engine that offered retention and downsampling as first-class concepts.

After trying indexes, monthly partitions, and an archive table, it became clear the engine should manage the lifecycle.
The data lifecycle should have been left to the storage engine.

A Short and Instructive Fling With InfluxDB

Our first candidate was InfluxDB; it was the first thing that came to mind when you said time series. The prototype was impressive: the same data took up 90 percent less space, and range queries were measured in milliseconds. Then we hit the cardinality wall. Once we modeled the device ID, driver ID, and alarm type as tags, the series count passed 4 million and memory usage spun out of control; the 16 GB test machine died with an OOM once a day. Reducing the tags fixed the memory, but then queries like "group by driver" got slow. There was also the cost of learning a separate query language nobody on the team knew; translating the hundreds of SQL queries in our reporting layer was a project in itself.

The TimescaleDB Decision and the Dual-Write Period

The second candidate was TimescaleDB. Being a PostgreSQL extension solved two things at once: our SQL knowledge still applied as is, and we could JOIN location data with the vehicle, customer, and driver tables. The hypertable structure made the partitioning we'd been running by hand far more fine-grained and automatic. With compression turned on, the 1.1 TB of data dropped to 96 GB; roughly 12x.

InfluxDB was ruled out because of cardinality and its query language; TimescaleDB was chosen for its SQL compatibility, JOIN support, and 12x compression.
Being a PostgreSQL extension solved two problems at once.

We didn't do the migration as a big bang. For six weeks we ran dual writes: every location packet went to both MySQL and TimescaleDB. During this period, a check job compared the end-of-day counts of the two systems, and in the first week it caught an embarrassing bug for us: in the time zone conversion, records that fell around midnight were being written to the wrong day. Without dual writes, the customer would have been the one to notice. We backfilled the historical data in chunks of 10 million rows during overnight windows; it took 11 nights in total.

We ran into a surprise on the write path as well. Devices don't always send data chronologically; a device coming back from a network outage can scatter packets from two days ago among today's packets. In MySQL nobody cared; in TimescaleDB, though, these late records arriving in older compressed chunks cause the chunk to be decompressed and recompressed, and when you do that hundreds of thousands of times, it shows. Our fix was to delay the compression window: a chunk isn't compressed until 7 days have passed; 99.9 percent of late data fits within that window. For the remaining tail of 0.1 percent, we kept a separate late-data buffer. Time series engines lean on the assumption of chronological writes; if you collect data from the field, don't move on without questioning that assumption.

Downsampling: This Is Where the Real Win Was

The biggest payoff of the migration wasn't the engine change; it was that we finally designed the data lifecycle. We kept raw location data for 90 days. With continuous aggregates, we produced 5-minute summaries for each device (average speed, distance traveled, alarm count) and kept them for 2 years. Daily summaries were kept indefinitely. The monthly mileage report now read the precomputed daily summary table instead of 940 million raw rows: the 4-minute query came down to 280 milliseconds.

Raw data is kept for 90 days, 5-minute summaries for 2 years, and daily summaries indefinitely; the monthly report reads the daily summaries.
The monthly mileage report dropped from 4 minutes to 280 milliseconds.

We also made a mistake here, and it was an expensive lesson. In the first downsampling schema, we had forgotten to include a "maximum speed" field in the summaries. When the 90 days were up and raw data started being deleted, we realized we had no data left for a retrospective speeding violation analysis an insurance company had requested. When you design your summary schema, the question to ask yourself shouldn't be "what reports exist today," but "two years from now, which question would I hate to have to say no to?" Before deleting raw data, prove for at least a quarter that the summaries really are enough.

The accounting on the hardware side is interesting too. To carry that table, our MySQL setup had swollen to a machine with 64 GB of RAM and NVMe disks, and it was still gasping for air. TimescaleDB does the same job on a 32 GB machine while leaving half the disk empty. Compression came with a side gift as well: backups. Because the nightly backup copied 96 GB instead of 1.1 TB, it went from 6 hours to 40 minutes, and its impact on the system became unnoticeable. The team's learning curve was gentler than we feared; the queries are SQL after all, and for someone coming from MySQL, PostgreSQL's EXPLAIN is a matter of a few weeks of getting used to. The thing that felt most foreign was the concept of chunks; getting used to the question "how many pieces is my table in?" took time.

Looking Back

Along the way, there was a culture shift in the reporting layer we didn't expect. Once queries got cheap, the product team started asking for screens we used to shy away from building because they would "wear out the database": hourly idling analysis, driving style scores, fleet comparisons. In other words, the performance work didn't just speed up existing screens; it expanded the product's imagination. The sneakiest cost of slow infrastructure is the features nobody dares to ask for.

This migration cost us four months and quite a few sleepless nights, but query times got 40 times shorter on average, storage costs dropped to a tenth, and the schema could breathe again. The most lasting lesson was this: the problem wasn't that MySQL was slow; it was that we diagnosed the character of our workload too late. If write-heavy, insert-based data that's queried by time is piling up, you need to design its lifecycle before the table reaches 100 million rows. We woke up at 940 million; don't wait that long. If you're on the verge of a similar migration and can't figure out where to start, write to us here; I'll gladly tell you what we went through.