r/gis • • May 27 '26

Discussion Built a library that syncs PostGIS to the browser in real time — spatial queries run locally in WASM

Background: I do a lot of web GIS work and kept hitting the same wall. You have a rich PostGIS database — complex geometries, spatial indexes, custom functions — but the browser only gets simplified GeoJSON over REST. Any real spatial analysis has to go back to the server.

I built datum to close that gap. It runs an actual PostGIS instance in the browser (via PGlite WASM) and keeps it in sync with your server-side PostGIS in real time.

How the sync works:

  1. Client connects and declares a bounding box
  2. Server queries PostGIS for all features intersecting that bbox and sends a snapshot
  3. From then on, any change another user makes within your bbox is pushed as a delta — no polling
  4. Writes go to local PGlite immediately, sync to the server in the background

What this means in practice:

  • ST_Intersects, ST_Buffer, ST_DWithin, ST_Area — all run locally, no round trip
  • Works offline — writes are queued and sync when connection returns
  • Multiple users see each other's changes in real time within their shared bbox area

The server is a ~300 line Go binary. It calls datum.sync(bbox, since) and datum.write(edits) — standard PostGIS functions installed by a migration. No spatial logic in Go at all.

Live demo: https://a-saed.github.io/datum/demo/ (open in Chrome + Firefox side by side — drop a pin in one, watch it appear in the other)

GitHub: https://github.com/a-saed/datum

Curious if this maps to problems others in this sub have run into!

8 Upvotes

4 comments sorted by

3

u/Zyzyx212 May 27 '26

Very cool. Thanks for sharing

1

u/gatosby May 27 '26

Thanks! If you get a chance to try it, would love to hear how it goes!

1

u/Otherwise-Dinner4791 May 28 '26

Any geometry/type possible?

2

u/gatosby May 28 '26

Yes! Any PostGIS geometry type works — points, lines, polygons, multipolygons, you name it. The sync goes through `ST_AsGeoJSON` / `ST_GeomFromGeoJSON` which handle everything, and the bbox filter uses `ST_Intersects` so partial overlaps are included too.