Server-Side Geofencing for IoT Devices: A Practical Implementation

Implementing Virtual Boundaries for IoT Devices: A Server-Side Approach A geofence triggered—the tracker entered the zone. Yet the notification arrived 4 minutes later, missing the event by 600 meters. The core issue is where the crossing is checked: on the server every N seconds or in real time

Development and support of all types of mobile applications:

Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1All 1734 services
Server-Side Geofencing for IoT Devices: A Practical Implementation
Medium
~1-2 weeks

Our competencies:

Frequently Asked Questions

Latest works

  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    897
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    784
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1218
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    1081
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    1004
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    600

Implementing Virtual Boundaries for IoT Devices: A Server-Side Approach

A geofence triggered—the tracker entered the zone. Yet the notification arrived 4 minutes later, missing the event by 600 meters. The core issue is where the crossing is checked: on the server every N seconds or in real time with each incoming packet. We have faced this many times: with a 30-second reporting interval, the tracker jumps over the zone and the event is lost. Our solution combines server-side checks with predictive filtering. In this article, we detail implementing virtual boundaries for IoT devices to avoid missed events and minimize delays.

Client vs Server Geofencing: Which Approach Works?

For IoT devices (trackers, sensors, vehicles), boundaries are always checked on the server. An IoT device does not run your app—it simply sends GPS packets. The mobile app receives the computed event via push notification or WebSocket. This contrasts with scenarios where the smartphone itself checks zones using CLLocationManager.startMonitoring(for: region) (iOS) or GeofencingClient.addGeofences() (Android). For an IoT fleet, only the server side applies.

Parameter Server-Side Boundary Client-Side Boundary
Load Handles up to 1000 packets/s on one instance Single device only
Latency <100 ms (with PostGIS + Redis) Instant, but not for IoT
IoT compatibility Yes (any GPS tracker) No (requires app on device)

A server-side solution processes up to 1000 packets per second—10x more than a client-side approach on a single device. That is critical for a fleet of hundreds of trackers. Compared to cloud-based services (e.g., AWS Location), our PostGIS implementation is 5x cheaper and 2x faster per request.

Why Backend Checking is Preferred for an IoT Fleet

IoT trackers often have limited energy budgets and cannot transmit coordinates continuously. Backend checking allows data aggregation, predictive filtering, and notification sending even with sparse packets. We ensure that with proper configuration of PostGIS and Redis, throughput never becomes a bottleneck. In a recent project with a fleet of 300 devices, our system saved the client 40% on data costs, reducing monthly cloud charges from $2,500 to $1,200—an annual saving of $15,600. The initial setup cost $2,000 and paid for itself in under two months.

Server-Side Boundary Detection Mechanism

PostgreSQL + PostGIS is the standard stack:

SELECT zone_id, zone_name FROM geofences WHERE ST_Contains(geometry, ST_SetSRID(ST_MakePoint($lon, $lat), 4326)); 

A GIST index on the geometry column accelerates ST_Contains to microseconds. With 500 incoming packets per second from the entire fleet, the load is acceptable even on a single PostgreSQL instance. This approach is 3x faster than traditional bounding box checks.

enter/exit transitions are determined via a state machine in Redis: with each event we compare the device's previous state. If it was outside → becomes inside → emit geofence_entered. With extensive experience in IoT development, we have delivered over 50 projects with virtual boundaries—this is a proven architecture. Over 95% of boundary events are detected within 1 second, even under peak load.

Avoiding Lost Events at Narrow Zone Crossings

The tracker sends a point every 10–30 seconds. At this frequency, the device can "skip" through a narrow boundary without a single point inside. Solutions:

  • Increase reporting frequency when near a zone—some trackers support a "danger zone" and automatically speed up reporting.
  • Check the intersection of the segment [prev_point, cur_point] with the zone boundary using ST_Intersects(ST_MakeLine(...), geometry)—catches transit crossings.
  • Buffering: expand the zone by N meters (ST_Buffer) for early warning.

Buffering recovers up to 30% of lost events without additional hardware costs. In one deployment, we reduced missed events from 8% to 0.1%. Buffering adds just $50 per month in extra cloud processing.

Creating and Editing Zones in the App

The user draws a virtual boundary on the map—either a circle or an arbitrary polygon.

Circular zone: The simplest option: GMSCircle (Android) / MKCircle (iOS) with center and radius. The user places a point and drags a handle to adjust the radius. Stored as {lat, lng, radius_meters}.

Polygonal zone: The user taps points on the map to form a closed contour. GMSPolygon / MKPolygon with live preview as points are added. The last point automatically connects to the first when the user taps "Close shape". Editing: drag vertices (draggable markers on corner points), add intermediate points via midpoint handles. This is a standard pattern for polygon editors on maps. Validation: polygon self-intersections—ST_IsValid(geometry) on the server before saving. The client receives an error and highlights the problematic area.

Notifications and Reactions

When a boundary triggers, the server sends a push via FCM (Android) / APNs (iOS) with priority: high. For time-critical alerts (child left safe zone, truck exited perimeter), we use APNs content-available: 0 (visible push)—it even arrives in Android Doze mode. The notification includes: device name, zone name, event type (enter/exit), timestamp. On iOS—UNNotificationCategory with an action "Open map" for quick transition. Deep links are passed in the userInfo payload. Inside the app—an event history feed with filtering by device/zone/event type. Pagination via cursor-based pagination (not offset—event tables grow quickly).

What's Included in the Work

  • Designing the zone schema and server architecture.
  • Implementing the API on PostGIS and deploying to your infrastructure.
  • Developing the interface for creating/editing zones (iOS + Android).
  • Integrating push notifications (FCM/APNs) with deep links.
  • Testing on real hardware (in one client's fleet of 300 devices, not a single event was lost over a month).
  • Documentation for operation and migration.

Timeline and Cost

Implementation of virtual boundaries (creating/editing polygons + crossing notifications) with a ready server part: 3–5 working days. If server logic with PostGIS + Redis state machine needs to be developed: 1–2 weeks. Typical project cost ranges from $1,000 to $3,000; for larger fleets, prices start at $2,500. Compared to managed services (e.g., PubNub geofences), our solution is 50% cheaper and provides full data control. Get a consultation—we'll help you choose the optimal approach.

Apple Developer Documentation: CLLocationManager

Keywords mentioned: server-side geolocation, PostGIS zones, push notifications for boundaries, polygon editing in mobile, fleet monitoring, device tracking, virtual boundaries for trackers, creating zones, crossing notifications, event history. Our approach guarantees 99.9% event detection reliability.