coursework · ZHAW

Cloud-Native Beacon System

AzureiOSSwiftWebSocket

What if you could replace the analogue doorbell in a store with something smarter? For the SCAD module, we built a cloud-native app that does exactly that. Customers install our iOS app, which scans for BLE beacons and notifies the store owner when someone walks in.

The app bridges the physical and digital worlds — smartphones detect Bluetooth beacons in the real world, and each detection triggers an event in our cloud-native, serverless backend on Azure.

Architecture

Overview - Build for Resilience

Overview

Functions

We use Azure Front Door to keep the application highly available. Two instances run in different Azure regions with equal-weighted, same-priority backends. Azure Front Door directs traffic to the nearest site and continuously monitors both. If one goes down, it provides automatic failover to the other.

Cosmos DB

  • The database has Availability Zones enabled to further improve availability and resiliency for our application.
  • Periodic backups take full backups of all partitions from all containers under your account, with no synchronisation across partitions. The minimum backup interval is 1 hour.
  • Global distribution

Frontend for Store Owners

Store owners access a web page where they can subscribe to events from specific locations. Since the application is event-driven, we use WebSockets via Azure Web PubSub to push notifications in real time — no polling needed in our serverless environment.

Notification

The Azure Function “negotiate” creates tokens for the frontend to access the Azure Web PubSub service. Another Azure Function called “notification” allows us to send messages through the PubSub system.

Unfortunately, we could not use the Azure Static Web Apps service. This would simplify the deployment by managing the frontend and APIs in one package. However, we ran into issues when using Azure Static Web Apps with extensions for Azure Web PubSub and also the “Bring your own Function”-button was not showing on portal.azure.com as documented.

App for Store Customers

The decision to build only an iOS app and skip Android was mainly driven by the available expertise in the team. Another reason is the deep integration of beacon monitoring iOS offers. However, this monitoring only works with beacons that support the iBeacon protocol. Luckily the Minew E9 Beacon supports this protocol. An iBeacon transmits its UUID, Major ID and Minor ID. We configured our beacons with different Major IDs. A Major ID represents a location or store.

Mockup

We used Apple’s CoreLocation framework to monitor beacons even when the app isn’t running in the foreground. All Minew E9 Beacons share the same iBeacon UUID (E2C56DB5-DFFB-48D2-B060-D0F5A71096E0). When iOS detects a beacon with this UUID, it wakes the app in the background for 10 seconds. The app then checks the distance to the beacon every second, and once you’re close enough, it triggers the gateway Azure Function.