Skip to content

Geofencing — Notes#

Functional#

  • Register polygonal / circular fences.
  • Watch devices; emit ENTER / EXIT / DWELL events.
  • Deliver via webhook / push / in-app.
  • Per-device per-fence state.

Non-functional#

  • p99 event latency < 5 s.
  • Tens of millions of fences; 100M+ devices.
  • 99.9% delivery for webhooks.

Capacity#

  • Location updates: millions/s.
  • Per update: index lookup + state update + maybe event emit.

Schema#

  • fences(id, owner, geometry, type, attrs)
  • subscriptions(fence_id, target, type)
  • device_state(device_id, fence_id, in_or_out, last_changed)

Trade-offs#

  • Server-side vs client-side geofencing: client saves bandwidth and battery (OS APIs); server centralizes business logic. Hybrid common.
  • R-tree vs S2/H3 cells: cells parallelize beautifully across shards; R-tree better for small fence counts.
  • At-most-once vs at-least-once with idempotency: usually at-least-once.

Refs#

  • Esri / PostGIS spatial indexing; Uber H3 docs; Mapbox / Radar geofencing platform docs; ByteByteGo "Design geofencing".