← All projects

Property Listings API

Listings for rent, sale and shortlet, and the search a property app actually runs: what is within X km of here, in my budget, with enough bedrooms.

The same 3 km query over 50,000 listings: ST_DWithin answered from a GiST index in 48ms, against 399ms for a sequential scan that computes a distance for every row

The problem

Built to a brief, with a clock on it: CRUD for listings, a search filtered by type, price range and bedrooms, and everything within X km of a point.

The last part is where the work is. The obvious implementation measures the distance from the search point to every listing and keeps the close ones. It returns the right answer and it reads every row in the table to do it. With two hundred listings nobody notices. With two hundred thousand, the search box is the slowest thing in the product.

What I built

The measurement that decided the design

Seeded to 50,000 listings, same radius, same machine:

Eight times faster at fifty thousand rows, and the gap widens with the table. That number is the whole reason for the PostGIS dependency, and it is in the README rather than in my head.

Decisions worth naming

What is not finished