Location Data Architecture in Vehicle Tracking Systems: Managing the Write Load

Vehicle tracking systems pose an interesting problem on the software side: the data model is very simple, but the load profile is very hard. A location record consists of just a few fields; yet a 500-vehicle fleet reporting at 10-second intervals produces more than 4 million rows a day. Let's pull together what we've learned on projects like this over the years.

The first mistake: keeping everything in one table

The most common pattern we see is the entire location history growing in a single konumlar table. The first six months go smoothly, then the map screen slows down, and then reports start timing out. The reason is simple: the same table is used both for very heavy writes and for time-range queries, and indexes can't do both well at once.

The separation we apply is this: current state and history live in different places. A small "last position" table holding a single row per vehicle feeds the map screen and always stays fast. History, meanwhile, accumulates in a time-based, partitioned structure.

Partitioning and retention policy

  • Partition the history table by date; monthly partitions are enough for most fleet sizes.
  • Dropping old partitions is many times faster than running row-by-row DELETE statements, and it doesn't create bloat.
  • Decide on the retention period together with business requirements and regulations; "keep everything forever" isn't a policy, it's a way of postponing the decision.
  • After a certain period, reduce raw records to a summarized form: per-minute averages and stop and idle summaries cover most reports.
Three layers: a last-position table for the map, a monthly partitioned history table and summarized records for reports.
Current state lives in a small table, history in a partitioned structure, and report data in summarized form.

Absorbing the write load

Running an individual INSERT for every packet coming from a device chokes the database with connection and transaction overhead as scale grows. Two interventions work on almost every project. The first is batch writes: buffering incoming packets over a short window (one to two seconds) and writing them in one go cuts the number of writes to a tenth. The second is queue separation: device endpoints only perform validation and drop the message onto a queue, while the heavy work (geofence checks, speeding violations, route matching) runs in the background. That way, device communication isn't affected by slow business rules.

Comparison of INSERTing every device packet individually versus using short-window batch writes and queue separation.
Batch writes and queue separation shield device communication from slow business rules.

Geospatial queries and indexes

For queries like "vehicles inside this polygon" or "stops within 500 meters of this point," ordinary indexes on latitude/longitude aren't enough. Using a spatial index with PostgreSQL + PostGIS brings the run time of the same query down from seconds to milliseconds. MySQL also offers spatial data types and indexes; the critical thing is to verify with the query plan that the query actually uses the index. Teams that skip this check think they've added an index and keep living with the same slowness.

An honest warning, too

Location data is personal data. When building a system that tracks individual drivers, you need to design access permissions, retention periods and who can see which report from the start. Adding this later is far more expensive, both technically and organizationally. Write role-based access into the data model from the very beginning.

The realities on the device side

No matter how well the software side is designed, devices in the field don't behave ideally. There are three situations you need to account for. The first is connectivity gaps: when a vehicle leaves coverage, the device buffers data in its own memory and sends it in bulk once it reconnects. So "the current time" and "the record's time" may not match, and the server has to order them correctly.

The second is clock drift: don't trust the device clock. While taking the record's timestamp from the device clock, also store the server's receive time in a separate column. The difference between the two turns out to be the most useful data when troubleshooting.

The third is noise: a stationary vehicle keeps producing small movements because of GPS accuracy limits. If you store these records without filtering, you accumulate unnecessary data and your "kilometers driven" reports come out higher than reality. A simple threshold filter (for example, skipping records when speed is zero and displacement is below a certain distance) significantly reduces data volume.

If you have a growing vehicle tracking or fleet management system, or you're building one from scratch, this is one of our areas of expertise. Write to us via our contact page; we can look at your current load profile and prioritize which intervention will pay off the most.