{
  "docVersion": 1,
  "id": "blog-gis-1",
  "name": "From GPS to a spatial query",
  "purpose": "A phone's GPS coordinate becomes a POINT geometry in SRID 4326, indexed by GiST, and answered by spatial queries — the write and read paths of location tracking.",
  "nodes": {
    "phone": {
      "type": "mobile",
      "label": "Driver phone",
      "x": 40,
      "y": 220,
      "w": 140,
      "h": 86,
      "runtime": "GPS: 28.61, 77.20"
    },
    "api": {
      "type": "gateway",
      "label": "Location API",
      "x": 320,
      "y": 220,
      "w": 140,
      "h": 86,
      "runtime": "every few seconds",
      "patterns": [
        "stateless"
      ]
    },
    "pg": {
      "type": "database",
      "label": "PostgreSQL + PostGIS",
      "x": 620,
      "y": 220,
      "w": 180,
      "h": 86,
      "color": "green",
      "runtime": "geography(Point,4326)",
      "notes": "The coordinate is stored as a POINT in SRID 4326 (WGS84 = raw GPS lat/lon). A GiST index on that column is what makes 'who's nearby?' fast."
    },
    "gist": {
      "type": "search",
      "label": "GiST index",
      "x": 620,
      "y": 420,
      "w": 140,
      "h": 86,
      "color": "amber",
      "runtime": "R-tree of bounding boxes"
    },
    "rider": {
      "type": "user",
      "label": "Rider app",
      "x": 1000,
      "y": 120,
      "w": 140,
      "h": 86,
      "runtime": "find drivers near me"
    },
    "q": {
      "type": "search",
      "label": "Spatial query",
      "x": 1000,
      "y": 320,
      "w": 160,
      "h": 86,
      "color": "blue",
      "runtime": "ST_DWithin · <-> KNN"
    }
  },
  "edges": {
    "e1": {
      "from": "phone",
      "to": "api",
      "fromSide": "right",
      "toSide": "left",
      "label": "lat,lng every ~4s",
      "animated": true
    },
    "e2": {
      "from": "api",
      "to": "pg",
      "fromSide": "right",
      "toSide": "left",
      "label": "UPSERT driver_loc = POINT(lng lat)",
      "animated": true
    },
    "e3": {
      "from": "pg",
      "to": "gist",
      "fromSide": "bottom",
      "toSide": "top",
      "label": "indexed",
      "style": "dashed"
    },
    "e4": {
      "from": "rider",
      "to": "q",
      "fromSide": "bottom",
      "toSide": "top",
      "label": "GET /nearby"
    },
    "e5": {
      "from": "q",
      "to": "gist",
      "fromSide": "left",
      "toSide": "right",
      "label": "index scan",
      "color": "blue"
    },
    "e6": {
      "from": "gist",
      "to": "pg",
      "fromSide": "right",
      "toSide": "bottom",
      "label": "matching rows",
      "color": "amber",
      "style": "dashed"
    }
  },
  "boxes": {
    "z1": {
      "x": 590,
      "y": 150,
      "w": 240,
      "h": 400,
      "label": "the durable store of truth",
      "color": "green",
      "opacity": 0.04
    }
  },
  "texts": {
    "t1": {
      "x": 40,
      "y": 420,
      "text": "SRID 4326 = WGS84 = the lat/lon your phone's GPS emits.\nstore raw GPS as geography and PostGIS does the earth-curvature\nmath for you — distances come back in real METERS.",
      "color": "green",
      "size": 12
    }
  },
  "meta": {
    "createdAt": "2026-07-21T09:00:00.000Z",
    "modifiedAt": "2026-07-21T09:00:00.000Z"
  }
}