Skip to content

Building a geospatial feature store with PostGIS, Elastic and DuckDB

Recently, I had the privilege to speak at FOSS4G NA 2026 about building a geospatial feature store using PostGIS, Elastic and DuckDB - a polyglot persistence system that I helped build. In my talk, I walked through how we solved a scale problem using an unconventional approach. Instead of vertically scaling a single database, we split the data and workload across different classes of databases and achieved high throughput while keeping cloud spend low. In this post, I walk you through the architecture and the lessons we learned.

A note on scale

I want to deflate the most common misconception about this kind of architecture, which is that it only makes sense for companies with enormous amounts of data, terabytes and trillions of records. In my experience, it only takes a couple of conflicting workloads to make a single database struggle. For example, one workload might be transactional, while another is analytical, and they can quickly step on each other's toes, especially if your data store is not built for both.

You don't need to be big to outgrow your database. You only need two workloads with diametrically opposed query patterns to clash.

The primary DB in this story holds roughly 150,000 customer records in the primary table and about 500,000 records of ancillary data split across leaf tables. These are primarily location data representing addresses, parcels and buildings. Apart from this, business intelligence data is stored in about 25 reference tables such as administrative boundaries, tax incentives, local ordinances and utility data. The BI data is used to enrich the customer records and is used in downstream processing. In the fourth quarter of 2025, the platform ran 15 million jobs, processing about 150,000 addresses a day and producing about 5 MB of output per address. That is a respectable workload, but it is nowhere near hyperscale, and I would argue that even at this mid-tier scale, the design choices I outline can start to pay off.

Executive summary

  1. PostGIS is a spatial database that is optimized for correctness, so we kept it as the home for business data, rules and transactions, and we stopped asking it to serve bursty, high-concurrency reads that it was never designed to absorb.
  2. Elasticsearch is a search engine that happens to understand geometry, which makes it a remarkably good home for reference layers that cover an entire market, since it scales horizontally and answers spatial queries in milliseconds.
  3. Parquet files on a blob store, queried in place with DuckDB, form the third tier we are moving toward for bulky analytical outputs, and it follows the same logic as the first two splits: once a pattern has worked twice, you earn the right to try it a third time.
  4. None of this is free. We traded a simple architecture for a performant one, and I will be upfront about the bill at the end.

Where we started

Version 1 of the software stack was the kind of architecture you would normally pick, nothing extraordinary: a cloud provider (GCP), a managed PostGIS instance (Cloud SQL with 4 vCPUs and 16 GB of memory) with high availability and one read replica, a Kubernetes (GKE) cluster running a task engine for background workloads, a few targeted microservices running on FastAPI, and a front end built with Vue for the customer.

Software stack diagram V1

Every time a location was analyzed, a job would pull that property's geometry and enrich it against all the reference layers (BI data), perform the computation and store it all back into the PostGIS instance. Everything, from customer data and BI data to the state of the jobs themselves, lived in one PostGIS database. This was a reasonable design for an early-stage system.

What PostGIS does well, and where it struggles

It would be unfair to tell this story as a complaint about PostGIS, which remains one of the finest pieces of open source engineering in the geospatial world. PostGIS gives you full ACID guarantees, so you can open a transaction, roll it back when something fails and trust that the database is always in a consistent state. It gives you hundreds of ST_ functions that cover nearly every spatial operation you are likely to need, a relational model that rewards careful normalization, mature spatial indexes and topology, and decades of tooling and managed hosting on every cloud. If the single metric you care about is correctness, PostGIS is the tool, and nothing I describe below changes that.

The trouble is that correctness and throughput are different virtues, and a system optimized for one pays a tax in the other. As our workload grew, and more importantly as the types of workloads diversified, the same four problems kept surfacing:

  • High-concurrency reads ran headlong into connection limits. As workloads grew, we hit a hard cap on the number of parallel workers for the task engine, since each worker established 4-8 connections to the database.
  • Read replicas helped, but they introduced replication lag between what we had just written and what our readers could see.
  • Map serving, in the form of dynamically generated mvt tiles or large GeoJSON responses, remained expensive when every pan and zoom on a busy map translated into a query.
  • Analytical scans choked transactional writes, because when all your business data lives in one place, people will inevitably run analytical questions against it, and a database cannot tell the difference between a customer saving their work and an analyst scanning a continent.

The last of these was the most noticeable, made worse by a new product line whose traffic was bursty and unpredictable, arriving in sharp spikes that were followed by long stretches of quiet. There is no comfortable way to size a database instance for that pattern, since sizing for the spikes means paying for idle capacity most of the year while sizing for the lulls means falling over when the spikes arrive. Vertical scaling only ever buys time because it scales the entire database, including the parts that are not under pressure. It became evident that we needed to solve this problem in a creative way.

Splitting the data by how we query for it

The instinct at this point is to start tuning the DB. In my opinion, tuning can be a trap, because it feels like progress and requires no one to change their mind about the architecture. We chose instead to ask a more fundamental question, which was how is each piece of data actually used? We discovered that we had two very different kinds of data, with respective query patterns, sharing one DB.

PostGIS and Elastic split

Core business data consists of customer data, the parcels and buildings being modeled, and the modeling results. It is relational and normalized, it is governed by constraints and business rules, it changes frequently, and above all it has to be right. This stayed in PostGIS, an engine optimized for correctness. A customer is only interested in their portfolio, so the queries are mostly scoped to that.

Reference data consists of nationwide parcels and buildings, administrative layers, local ordinances, tax and rebate programs, and utility and capacity data. It covers the entire addressable market rather than just our customers' corner of it, it moves slowly because nobody redraws a county boundary every afternoon, and it is read constantly by everything else in the system. We moved this to Elasticsearch, along with denormalized, aggregated views of customer data that the application needed to read quickly. The queries here are mostly read-heavy and cover larger, amorphous geographies, where Elastic's speed really helps.

The resulting architecture is only one box away from the original, which is a point worth dwelling on, since most good architectural changes are subtle on the diagram but big in effect.

Stack v2

How PostGIS and Elastic actually do spatial

At this point, it would be beneficial to compare how PostGIS and Elastic handle spatial data. The two tools share a vocabulary of points and polygons, but they come from entirely different lineages, one from the world of relational databases and the other from the world of search.

PostGIS Elasticsearch
Geometry types geometry, geography, raster, topology, 3D geo_point, geo_shape
Spatial operations Hundreds of ST_ functions: overlay, buffer, union, area, simplify Spatial relations (intersects, within, contains, disjoint), distance, bbox
Coordinate systems Thousands of CRS, with reprojection WGS84 lat/lon only
Precision Exact computation Approximate, tuned for speed
Joins Native SQL joins, including spatial joins between layers Weak support. Denormalize before you ingest
Output GeoJSON, WKB, MVT via ST_AsMVT GeoJSON, MVT

The best way to read this table is as a list of what you should not ask Elastic to do, because there is no buffering, no union, no reprojection and no relational join to lean on, and any question that needs them either belongs in PostGIS or has to be added on top via some custom adapter. However, if your question is "give me everything that intersects this polygon, or this bounding box, right now, for a thousand people at once," then you have the kind of problem Elastic was built for. This philosophy can be summarized as:

PostGIS is a spatial database. Elastic is a search engine that understands geometry.

Playing each to its strength

Once you accept that framing, a series of design decisions follow naturally:

  • Updates work differently in each world. PostGIS updates rows in place inside a transaction, whereas Elastic indices are best treated as immutable, so to refresh a layer we bulk write a brand new index and then swap the alias. Since we stored fast-changing customer data in PostGIS and slower changing reference / market data in Elastic, this pattern of updates works well. We seldom need to update a single county's geometry whereas we frequently add, update, or remove records pertaining to individual customers.
  • Responsibilities divide naturally, with PostGIS upholding the business rules enforced at the DB level and Elastic taking care of serving high-velocity reads and absorbing bursty reads and writes.
  • Scaling now happens independently for each tier, so we could scale PostGIS down vertically once it was freed from the read traffic and scale Elastic out horizontally when needed. This was a big relief for our infrastructure planning.

Harmony with vector tiles

One pleasant side effect shows up in the map. Each layer lives in a predetermined store, so PostGIS-backed layers come back as GeoJSON while Elastic-backed layers come back as Mapbox Vector Tiles, and the front end happily consumes both. When a user pans across the map, the browser asks for tiles at particular zoom levels, and a thin service translates each request into an Elasticsearch search_mvt query that returns only the features intersecting that tile and streams it back. A user can therefore move smoothly around a map of more than 100,000 features without straining client-side resources, because the web app renders only tiles rather than a full GeoJSON payload of features.

A few scheduled ETL pipelines running on Kubernetes keep that body of market data fresh. For certain queries, we also denormalize customer data and ingest it into Elastic. Patterns like bulk-write and alias-swap allow for zero-downtime updates.

If it works, repeat it: adding DuckDB

Once we drove a wedge into the primary DB with the aim of splitting the data (into PostGIS and Elastic), we started seeing more avenues to optimize storage. The modeling engines in the platform produce large outputs in the form of simulation results, which are mostly numerical, and we had been storing them in PostGIS. But these are bulky analytical artifacts rather than transactional records, and that profile suits neither PostGIS nor Elastic. This meant there was yet another opportunity to rethink where they live.

The cloud-native geospatial ecosystem has matured enormously over the past few years, and it offers a clean answer: write the outputs as Parquet or GeoParquet files on a blob store, and query them in place with DuckDB, which uses range reads to fetch only the bytes a query actually needs. Organize those files in a STAC-compatible way and you gain a standard means of discovering them as well. I would describe this tier as the direction we are heading in rather than a victory lap, but the reasoning behind it is sound, because query traffic against this data is low, so the DuckDB service can be made serverless, costing almost nothing when idle.

Architecture diagram, version 3

Tier Holds Strength
PostGIS Business data and rules, simulations tied to customer records Transactional safety, relational integrity, rich spatial operations
Elastic Reference layers covering the full market, denormalized customer aggregates Horizontal scaling, sub-second queries, high-volume writes
Blob store + DuckDB Full modeling outcomes, geometries, financial models Cheap storage, Parquet, range reads, scale-to-zero compute

Conclusion

We started with a single database for everything, which seemed simpler at first; however, as the data grew and workloads diversified, that simplicity quickly faded. Instead of vertically scaling one DB system, we split the data across specialized stores, each with different roles and strengths. Thus, we traded architectural simplicity for performance, but the results were promising. The trade-offs are worth stating plainly:

  • More moving parts. There are more services, more synchronization jobs and more ETL to write, monitor and wake up for at three in the morning.
  • Polyglot persistence is genuinely hard. Data versioning and migrations across three stores are non-trivial. When writes fail, there is no single transaction that can undo everything. Thus, consistency is something we need to design and manage carefully.
  • Updating layers in Elastic is near real-time but cumbersome, since the bulk-write-and-swap dance is reliable but involves a good deal more ceremony than a plain UPDATE.
  • Query hygiene is important. We cannot repeat the same mistakes by asking Elastic to do what PostGIS is designed for, and vice versa.

In our case, standing up Elastic turned out to be both easier and more cost-effective than continuing to tune PostGIS. That judgment is specific to our situation, and if your traffic is small and steady, then one well-run database is almost certainly the right answer.

Resources