Back to All Stories
EngineeringEnglish27 Agustus 20264 min read269 views

Thawaf App: Engineering a Smart Digital Companion for Millions of Pilgrims

How Lontarlab engineered Thawaf App (thawaf.id) — solving ultra high-density crowd telemetry, offline-first vector maps, automated Tawaf counting, and instant SOS emergency dispatch across the Holy Sites.

Rifky Abdul Hanan

Rifky Abdul Hanan

Software Development Manager at Lontarlab

Thawaf App: Engineering a Smart Digital Companion for Millions of Pilgrims

1. The Challenge: Engineering for Millions in Extreme Crowd Density

The annual Hajj and Umrah pilgrimages bring together millions of pilgrims from over 160 countries across the Holy Sites of Makkah, Mina, Muzdalifah, and Arafah. In such dense crowd environments, conventional mobile apps struggle: cellular base stations become saturated, GPS signals suffer severe multipath interference from tall surrounding structures, and pilgrims face physical exhaustion and navigation hurdles.

“To engineer a mission-critical digital companion that guides, protects, and empowers every pilgrim with real-time location precision, offline-first reliability, and seamless emergency response.”

2. Core Architectural Pillars of Thawaf App

01. TELEMETRY

Sensor-Fused Kinetic Geolocation

Merges accelerometer, gyroscope, and compass data with sparse GPS signals to accurately track pilgrim motion and group members even in GPS-denied corridors.

02. OFFLINE

Offline-First Vector Mapping

Embedded 45MB compressed vector map directory containing exact tent numbers in Mina, medical clinics, assembly gates, and direct Kaaba bearings without requiring internet.

03. AUTOMATION

Smart Tawaf & Sa'i Circuit Counter

Polygon geofences around the Kaaba trigger subtle haptic vibration cues on lap completion and automatically cycle through authentic contextual Arabic and Latin prayers (Du'a).

04. SAFETY

Zero-Latency SOS Emergency Dispatch

Single-tap emergency broadcast that dispatches encrypted spatial coordinates, medical info, and emergency contacts to Muthawif group leaders via multi-channel fallback.

3. Real-Time Geofencing & Circuit Calculation Engine

During the Tawaf ritual around the Holy Kaaba, GPS signals can jitter rapidly due to the dense crowd and high surrounding architectural walls. To guarantee reliable lap detection without battery drain, Thawaf App employs a custom radial angle accumulator in Flutter/Dart, computing cumulative angular displacement relative to the Kaaba center coordinate (21.4225° N, 39.8262° E).

snippet.ts
1import 'dart:math' as math;
2import 'package:flutter/services.dart';
3import 'package:latlong2/latlong.dart';
4
5class TawafCircuitEngine {
6 static const LatLng kaabaCenter = LatLng(21.422487, 39.826206);
7 static const double greenLightBearingRad = 2.1467; // Starting line alignment
8
9 int currentLap = 0;
10 double accumulatedRadianDelta = 0.0;
11 double previousAngle;
12
13 /// Ingest raw GPS & sensor fusion position
14 void processKineticPosition(LatLng pilgrimLocation) {
15 final double dy = pilgrimLocation.latitude - kaabaCenter.latitude;
16 final double dx = pilgrimLocation.longitude - kaabaCenter.longitude;
17 final double currentAngle = math.atan2(dy, dx);
18
19 if (previousAngle != null) {
20 double delta = currentAngle - previousAngle!;
21
22 // Normalize angle wrap-around (-PI to +PI)
23 if (delta > math.pi) delta -= 2 * math.pi;
24 if (delta < -math.pi) delta += 2 * math.pi;
25
26 // Anti-clockwise Tawaf progression
27 if (delta > 0) {
28 accumulatedRadianDelta += delta;
29 }
30
31 // 2 * PI radians represents 1 full Tawaf circuit (360 degrees)
32 if (accumulatedRadianDelta >= (2 * math.pi)) {
33 currentLap++;
34 accumulatedRadianDelta -= 2 * math.pi;
35 _triggerLapMilestoneNotification(currentLap);
36 }
37 }
38
39 previousAngle = currentAngle;
40 }
41
42 void _triggerLapMilestoneNotification(int lap) {
43 HapticFeedback.heavyImpact();
44 // Dispatch telemetry packet to Muthawif group leader
45 }
46}

4. High-Throughput Spatial Ingest Pipeline

On the server side, thousands of concurrent pilgrim telemetry events are ingested using an asynchronous Node.js and Redis Pub/Sub stream worker. Telemetry packets are validated, geohash-indexed, and stored in PostgreSQL with PostGIS spatial indexes.

snippet.ts
1import { createClient } from "redis";
2import { query } from "@/app/lib/db";
3
4interface TelemetryPacket {
5 pilgrimId: string;
6 groupId: string;
7 latitude: number;
8 longitude: number;
9 batteryLevel: number;
10 sosActive: boolean;
11 timestamp: number;
12}
13
14export async function processTelemetryBatch(packets: TelemetryPacket[]): Promise<void> {
15 const redis = createClient({ url: process.env.REDIS_URL });
16 await redis.connect();
17
18 for (const packet of packets) {
19 // 1. Publish to real-time Muthawif group room
20 await redis.publish(
21 `group:${packet.groupId}:telemetry`,
22 JSON.stringify(packet)
23 );
24
25 // 2. High-priority alert queue if SOS emergency is active
26 if (packet.sosActive) {
27 await redis.lPush("queue:emergency_sos", JSON.stringify(packet));
28 }
29 }
30
31 // 3. Asynchronously batch persist to PostgreSQL / PostGIS database
32 await query(
33 INSERT INTO pilgrim_telemetry (pilgrim_id, group_id, geom, recorded_at)
34 SELECT x.pilgrim_id, x.group_id, ST_SetSRID(ST_MakePoint(x.longitude, x.latitude), 4326), NOW()
35 FROM JSON_TO_RECORDSET($1) AS x(pilgrim_id text, group_id text, longitude float8, latitude float8),
36 [JSON.stringify(packets)]
37 );
38}

5. Comprehensive Ecosystem Synergy: SaaS & Global Connectivity

Beyond the mobile application for pilgrims, the Thawaf ecosystem integrates with dedicated B2B platforms engineered by Lontarlab:

1.Sama Al Thawaf Portal (samaalthawaf.id): A centralized group management and room-allocation suite empowering travel agencies to monitor their pilgrims live on spatial maps.
2.International Roaming Suite (paketinternet.thawaf.id): Direct eSIM and multi-operator data package provisioning, removing the friction of purchasing local SIM cards on arrival in Jeddah and Madinah.
3.Muthawif Live Dispatch: Real-time bi-directional messaging and voice broadcast announcements to coordinate bus departures and prayer assemblies smoothly.

6. Download and Experience Thawaf App

Thawaf App is available for download on both Google Play Store and Apple App Store. Learn more and partner with Lontarlab at https://thawaf.id.
Rifky Abdul Hanan

Written by Rifky Abdul Hanan

Author

Software Development Manager at Lontarlab. Passionate about software architecture, distributed systems, user-centric product engineering, and mentoring future builders.