Logs, Mobile Apps and IoT
PedalCity's dock sensors report every 30 seconds, the mobile app records taps, and the servers write log lines. This is event data: a record of something that happened at a moment in time. It is the largest source PedalCity has, and the least tidy. A phone in a tunnel keeps its events for an hour. A sensor that did not hear an acknowledgement sends the same reading twice.
The rule
Events arrive late, twice, and out of order — design for it.
Every event carries two times:
- Event time: when it actually happened, stamped by the device.
- Arrival time: when your pipeline received it.
They can be far apart. A rider taps "unlock" at 08:02 in an underground car park, and the phone uploads the event at 09:10. Count by arrival time and the tap lands in the 09:00 hour, so 08:00 looks too quiet and 09:00 too busy.
{"event_id": "e-7f3a", "type": "unlock_tapped", "rider_id": 5521,
"event_time": "2026-09-24T08:02:11+05:30",
"arrival_time": "2026-09-24T09:10:57+05:30"}Three habits handle the mess:
- Deduplicate by a unique ID. Give each event an
event_idat the source. If the same ID arrives twice, keep one copy. - Group by event time, not arrival time, when the question is about when things happened.
- Allow lateness. Keep each hour's result open for a while, say two hours, and recompute it when late events arrive.
Logs add one more step. Server logs are text lines that must be parsed into fields before they are useful, and lines can be malformed:
2026-09-24 08:14:03 INFO dock=17-04 bike=903 action=dockedDevice clocks also drift. A sensor with a wrong clock can send "future" events, so check timestamps against sensible bounds.