Edge and on-premise#
SurfaceLens runs on Cloudflare's network. An airport that must keep working through a loss of connectivity also runs an on-premise node: the same API, the same keys, holding the last 72 hours of the airport's model.
The on-premise node and failover arrive in Preview 2. Preview 1 runs on the edge only.
The edge#
Every request to https://api.surfacelens.app/v1 is answered by a Worker in the Cloudflare data centre nearest the caller. The Worker authenticates the key, checks scopes and serves reads. Writes, and the authoritative history for each airport, live in the airport's home region: apac for VTBS. An airport's data is stored only in its home region; the edge caches nothing that outlives a request.
There is no regional host name to choose. The response header SurfaceLens-Node names the node that answered, for example edge; colo=BKK.
The on-premise node#
Airports that must keep operating through a loss of their internet connection install an on-premise node: a container image that runs on two or more servers inside the airport network. The node:
- holds a replica of the airport's model for the last 72 hours, kept current from the edge, typically less than a second behind;
- serves the same v1 API at its own base URL, published on the airport object as
onprem_node; - accepts the same keys, synchronised from the edge, with revocations applied within 60 seconds.
The node does not run scenarios or send webhooks; both resume on the edge when it returns.
Primary and standby#
For each airport, one node is primary: it admits observations and assigns revisions. Normally that is the edge, and the on-premise node is standby.
If the on-premise node loses contact with the edge for 30 seconds, it promotes itself to primary for the airport network, and the airport's epoch increases by one. Clients inside the airport switch to it. Clients outside keep using the edge, which goes on admitting the feeds that still reach it.
When contact returns, the two exchange the observations each admitted during the split. Observations are immutable and carry their source record IDs, so merging them never conflicts: each is admitted once, attribute values settle by the usual feed priority, and the epoch increases again. The node returns to standby.
GET /v1/status on either node reports its role, epoch and lag. See Retrieve node status.
What a client sees#
- Reads
- The same responses from either node, up to replication lag. Reads older than 72 hours on the node are forwarded to the edge, or fail with
time_out_of_rangewhile the edge is unreachable. - Writes
- Records pushed to either node are admitted once. Retrying a batch on the other node after a timeout is safe, because records are deduplicated by
record_id. - Streams
- Event IDs have the form
epoch:revision. Reconnect to either node withLast-Event-IDand the stream resumes without gaps. After a merge, the stream first re-sends the state of entities the merge changed. - Errors
- A node that is not primary for a write it cannot forward returns
503 not_primarywith the other node's base URL indetail.
The rules for when to switch, and code that implements them, are in Fail over to on-premise.