The problem with a property platform is not traffic, it is data
Anyone designing a listings portal thinks about scale straight away: millions of pages, map searches, notifications. But the first piece to break, and the one that stays broken longest, is the data. A listing arrives from ten agencies in ten formats, the same flat shows up twice with an address spelled differently, a "negotiable" price ends up in a numeric column. If the platform does not settle on a single shape for the data before scaling everything else, every downstream component (search, alerts, valuation) inherits the mess and multiplies it.
This article opens the series with the three decisions that hold everything else up: how to model a property as distinct from its listing, how to let an external feed in without trusting it, and how to paginate a long list without making the database pay more for each page than for the previous one. The listings were compiled and run: the TypeScript with Node 24, the SQL with PostgreSQL 17.
Property, listing and source are three different things
The most common modelling mistake is a single table, annunci, with everything inside it. It
works as long as every flat has exactly one listing. Then an agency withdraws the listing and republishes
another at a different price, an owner hands the same property to two agencies, and the price history of
that flat breaks into four unrelated rows. That is why it pays to separate the three concepts from the
start:
- Property: the physical thing. Address, floor area, year, coordinates. It changes rarely and has a long life.
- Listing: an offer of that property by someone. It has a price, a status, dates, and a property can have many of them over time or at the same moment.
- Source: where the listing comes from (an agency, a feed, a direct entry) and the key the source uses to call it.
The order of the three items is not a detail: the relationship runs many-to-one, from listing to property, and from source to listing. Everything the rest of the platform wants to know about prices over time is computed on the chain of listings of one property, which exists only if the property is an entity in its own right. It is the same choice that, in the article on automated valuation, gives us a clean history to learn from.
Letting a feed in without trusting it
The reference standard for exchanging real estate data is the RESO Data Dictionary,
which gives fields a common name: ListingKey for the listing key, ListPrice
for the price, LivingArea for the floor area, StandardStatus for the status.
Having it as a common language does not mean the data is clean. The listing below is the entry boundary:
it reads a record with RESO names, turns it into the internal model and rejects whatever it cannot
explain.
type RecordRESO = Record<string, unknown>;
type Stato = 'attivo' | 'in_trattativa' | 'chiuso' | 'ritirato';
interface Annuncio {
chiaveSorgente: string;
stato: Stato;
prezzoEuro: number;
superficieMq: number;
locali: number;
lat: number;
lon: number;
}
// RESO's StandardStatus has more values than the product tells apart.
const STATI: Record<string, Stato> = {
Active: 'attivo',
ComingSoon: 'attivo',
Pending: 'in_trattativa',
ActiveUnderContract: 'in_trattativa',
Closed: 'chiuso',
Canceled: 'ritirato',
Withdrawn: 'ritirato',
Expired: 'ritirato',
};
function numeroPositivo(v: unknown, campo: string): number {
const n = typeof v === 'string' ? Number(v) : v;
if (typeof n !== 'number' || !Number.isFinite(n) || n <= 0) {
throw new Error(`${campo} non valido: ${JSON.stringify(v)}`);
}
return n;
}
export function normalizza(r: RecordRESO): Annuncio {
const stato = STATI[String(r['StandardStatus'])];
if (!stato) throw new Error(`StandardStatus sconosciuto: ${r['StandardStatus']}`);
return {
chiaveSorgente: String(r['ListingKey']),
stato,
prezzoEuro: numeroPositivo(r['ListPrice'], 'ListPrice'),
superficieMq: Math.round(numeroPositivo(r['LivingArea'], 'LivingArea')),
locali: numeroPositivo(r['BedroomsTotal'], 'BedroomsTotal'),
lat: Number(r['Latitude']),
lon: Number(r['Longitude']),
};
}
const feed: RecordRESO[] = [
{ ListingKey: 'A-1', StandardStatus: 'Active', ListPrice: '245000', LivingArea: 78.4, BedroomsTotal: 2, Latitude: 40.352, Longitude: 18.174 },
{ ListingKey: 'A-2', StandardStatus: 'Pending', ListPrice: 310000, LivingArea: 102, BedroomsTotal: 3, Latitude: 40.361, Longitude: 18.169 },
{ ListingKey: 'A-3', StandardStatus: 'Active', ListPrice: 'trattabile', LivingArea: 60, BedroomsTotal: 1, Latitude: 40.35, Longitude: 18.17 },
{ ListingKey: 'A-4', StandardStatus: 'Hold', ListPrice: 190000, LivingArea: 55, BedroomsTotal: 1, Latitude: 40.34, Longitude: 18.18 },
];
const buoni: Annuncio[] = [];
const scartati: { chiave: string; motivo: string }[] = [];
for (const r of feed) {
try {
buoni.push(normalizza(r));
} catch (e) {
scartati.push({ chiave: String(r['ListingKey']), motivo: (e as Error).message });
}
}
console.log('accettati:', buoni.map((a) => `${a.chiaveSorgente}=${a.stato}/${a.prezzoEuro}`).join(', '));
console.log('scartati :', JSON.stringify(scartati));
// Output:
// accettati: A-1=attivo/245000, A-2=in_trattativa/310000
// scartati : [{"chiave":"A-3","motivo":"ListPrice non valido: \"trattabile\""},{"chiave":"A-4","motivo":"StandardStatus sconosciuto: Hold"}]
Two choices matter more than the others. The first is the STATI table:
StandardStatus has more values (Active, ActiveUnderContract, Pending, Closed, Canceled,
Expired, Withdrawn and others) than the product tells apart, so we reduce them to four internal states. An
unmapped value, such as Hold in the last test record, raises an error instead of falling into
a generic "other": a listing with an unknown status must not show up among the active ones by mistake. The
second is numeroPositivo, which accepts the price both as a number and as a numeric string
(real feeds mix the two) but rejects "trattabile" (negotiable), zero and negative values.
The output shows the result: two records accepted and two rejected, each with its reason. Rejecting with a
reason is the part that saves the work afterwards: a record rejected silently is a listing the customer
never sees and nobody knows why, whereas a record rejected with a reason ends up in an anomaly queue that
someone can read and fix at the source. What this code does not do: it does not look at
the coordinates (Number(undefined) would give NaN without an error), and in a
real system a range check should be added before trusting lat and lon.
The same flat, two listings: the address key
When two agencies publish the same flat, the user sees two identical results and the platform computes the same price per square metre twice. The simplest way to notice is to build a normalised address key for every listing and group on it. The listing strips accents, capitals and punctuation, and keeps the parts of the address apart with a character that cannot appear in the data.
// The same flat arrives from two agencies with addresses written differently.
function chiaveIndirizzo(via: string, civico: string, interno: string, cap: string): string {
const pulita = via
.toLowerCase()
.normalize('NFD')
.replace(/\p{M}/gu, '') // strips the accents
.replace(/[^a-z0-9 ]/g, ' ')
.replace(/\s+/g, ' ')
.trim();
return [pulita, civico.toLowerCase().replace(/[^a-z0-9]/g, ''), interno.toLowerCase().replace(/\W/g, ''), cap].join('|');
}
const annunci = [
{ fonte: 'agenzia-nord', id: 'N-77', via: 'Via Dei Mille', civico: '12/A', interno: 'int. 3', cap: '73100', prezzo: 189000 },
{ fonte: 'agenzia-sud', id: 'S-9', via: 'via dei mille', civico: '12 A', interno: 'Int.3', cap: '73100', prezzo: 185000 },
{ fonte: 'agenzia-sud', id: 'S-11', via: 'Via dei Mille', civico: '12/B', interno: 'int 3', cap: '73100', prezzo: 199000 },
{ fonte: 'agenzia-sud', id: 'S-10', via: 'Via Giovanni Pàscoli', civico: '4', interno: '', cap: '73100', prezzo: 120000 },
];
const gruppi = new Map<string, typeof annunci>();
for (const a of annunci) {
const k = chiaveIndirizzo(a.via, a.civico, a.interno, a.cap);
gruppi.set(k, [...(gruppi.get(k) ?? []), a]);
}
for (const [k, g] of gruppi) {
console.log(`${k} -> ${g.map((x) => `${x.fonte}:${x.id}@${x.prezzo}`).join(' + ')}`);
}
// Output:
// via dei mille|12a|int3|73100 -> agenzia-nord:N-77@189000 + agenzia-sud:S-9@185000
// via dei mille|12b|int3|73100 -> agenzia-sud:S-11@199000
// via giovanni pascoli|4||73100 -> agenzia-sud:S-10@120000
In the result, the two listings for via dei Mille 12 interior 3 land in the same group, even though one writes "Via Dei Mille", "12/A" and "int. 3" and the other "via dei mille", "12 A" and "Int.3". The detail that costs is the street number: if the key kept only the digits, 12/A and 12/B would collapse into the same property, and two different flats would be merged. That is why the code keeps the letters too, and 12/B stays a separate group. The opposite trade-off exists and is the one to know: the stricter the key, the more duplicates slip through (a "12 bis" does not match a "12/B"); the looser it is, the more different properties get merged. A text key is a cheap first filter; the next step, which we do not show here, compares coordinates and floor area to settle the doubtful cases and leaves the last word to a person.
Paginating without making deep pages expensive
Pagination with OFFSET seems natural: page 5000, skip 100,000 rows. The problem is that the
database does not "skip": it reads them and throws them away. Page 1 costs little, page 5000 costs a
thousand times more, and a crawler that walks the list to the end makes the platform pay the highest bill.
Cursor (keyset) pagination avoids the problem: instead of saying "skip N rows", it says
"give me the ones after the last one you saw".
DROP TABLE IF EXISTS annuncio;
CREATE TABLE annuncio (
id bigint PRIMARY KEY,
prezzo integer NOT NULL,
citta text NOT NULL
);
INSERT INTO annuncio
SELECT g, 80000 + (g * 7919) % 400000, 'Lecce'
FROM generate_series(1, 200000) AS g;
CREATE INDEX annuncio_prezzo_id ON annuncio (citta, prezzo, id);
ANALYZE annuncio;
-- Page 1: the first 3 by ascending price, ties on price are broken by id.
SELECT id, prezzo FROM annuncio WHERE citta = 'Lecce' ORDER BY prezzo, id LIMIT 3;
-- Page 2: the cursor is the last row seen, (80003, 53037). No OFFSET.
SELECT id, prezzo FROM annuncio
WHERE citta = 'Lecce' AND (prezzo, id) > (80003, 53037)
ORDER BY prezzo, id LIMIT 3;
-- How the database runs it: look at "Index Cond" and the absence of Sort.
EXPLAIN (COSTS OFF)
SELECT id, prezzo FROM annuncio
WHERE citta = 'Lecce' AND (prezzo, id) > (80003, 53037)
ORDER BY prezzo, id LIMIT 3;
-- The cost of OFFSET: to reach row 100001 the database reads the 100000 before it.
-- Look at "actual rows" on the Index Only Scan node, not at the time.
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF)
SELECT id, prezzo FROM annuncio
WHERE citta = 'Lecce' ORDER BY prezzo, id OFFSET 100000 LIMIT 3;
-- Output:
-- id | prezzo
-- -------+--------
-- 17679 | 80001
-- 35358 | 80002
-- 53037 | 80003
-- (3 rows)
--
-- id | prezzo
-- --------+--------
-- 70716 | 80004
-- 88395 | 80005
-- 106074 | 80006
-- (3 rows)
--
-- QUERY PLAN
-- -----------------------------------------------------------------------------------------
-- Limit
-- -> Index Only Scan using annuncio_prezzo_id on annuncio
-- Index Cond: ((citta = 'Lecce'::text) AND (ROW(prezzo, id) > ROW(80003, 53037)))
-- (3 rows)
--
-- QUERY PLAN
-- -----------------------------------------------------------------------------------------
-- Limit (actual rows=3 loops=1)
-- -> Index Only Scan using annuncio_prezzo_id on annuncio (actual rows=100003 loops=1)
-- Index Cond: (citta = 'Lecce'::text)
-- Heap Fetches: 100003
-- (4 rows)
The line that does the work is (prezzo, id) > (80003, 53037). PostgreSQL's row comparison
compares the elements from left to right and stops at the first pair that differs
(section 9.25.5 of the documentation),
so it is equivalent to "price greater, or price equal and id greater". The trailing id is not
decorative: it is the tie-breaker, without which two listings at the same price could appear in both pages
or in neither. The plan shows the condition inside the Index Cond of the
(citta, prezzo, id) index and there is no Sort node: the database starts at the
right point of the index and reads only three entries.
The last query, with OFFSET 100000, makes the opposite cost visible: the
Index Only Scan node reports actual rows=100003, that is, it read a hundred
thousand rows to return three. We chose to show the row count instead of the time, because time changes
from machine to machine and the count does not. The price to pay with the cursor is that you cannot jump
straight to page 5000: you can only go forward and back. For a listings portal that is fine, because
people looking for a home refine their filters more often than they browse to page 5000.
Where to cut the services: writing and reading have opposite needs
With the three-entity model it also becomes clear where it makes sense to split the system. Whoever writes data (the agencies publishing, the ingestion job) needs transactions and constraints: a listing does not exist without its property. Whoever reads (the visitors searching) needs answers in a few milliseconds on combined filters, and tolerates seeing a price change with a few seconds of delay. These are two loads with opposite needs, and keeping them in the same database means a heavy search slows publishing and the other way round.
The classic solution is a separate read model, fed from the write database through events: search queries an optimised copy, and the cost is eventual consistency. It is a compromise to declare to the product before the code, because if the seller lowers the price and the card still shows the old one for a few seconds, someone must have decided that this is fine. For a small platform a single model with the right indexes is enough and costs less to run: splitting into services before you need to is a debt, not an architecture.
Where the other pieces live
Radius search, polygons and the map have an article of their own, the one on geospatial search with PostGIS: here it is enough to keep in mind that the spatial index goes on the properties table, not on the listings one, because the coordinates belong to the physical thing. Text search on the listings, with accents, plurals and typos, is in the article on full-text search with PostgreSQL. The continuous flow of price changes, which feeds alerts and indicators, is the subject of the real-time data pipeline; how to make the alert for a change arrive exactly once, with the outbox and offsets, is shown by the article on listing events. And everything concerning the personal data of people looking for a home, from erasure to the risk of discrimination, is in the article on privacy and compliance. For how the building itself is described, and not only the listing that puts it on sale, see the article on BIM. How to show a property with a 360-degree panorama, and the memory it costs, is in the article on virtual tours.
One architectural constraint applies from here on: Regulation (EU) 2016/679 gives the data subject the right to erasure of their personal data (Article 17), with the exceptions provided for by the same article. If the data of someone who wrote to an agency is scattered across logs, caches and search indexes, erasure becomes a project. It is therefore worth keeping the personal data of enquirers in a few well-identified tables, separate from the property catalogue, which is not personal data.
What you can do now
You can separate property, listing and source in a model that holds up the price history; you can write an
entry boundary that accepts, rejects with a reason and lets no unknown status through; you can recognise
the same property in two listings and you know the trade-off of the address key; and you can paginate a
long list at constant cost, with the reason why the id must be in the cursor. What we did not
measure here, and what depends on your load, is behaviour under real traffic: the listings are the shape of
the data, not a benchmark.
Sources
- RESO Data Dictionary 2.0, StandardStatus field - the standard values of the listing status (Active, Pending, Closed, Withdrawn and others), accessed on 2026-11-12
- RESO Data Dictionary 2.0, LivingArea field - the definition of living area used in the normaliser, accessed on 2026-11-12
- PostgreSQL 17, section 9.25 Row and Array Comparisons - the left-to-right row comparison the cursor relies on, accessed on 2026-11-12
- Regulation (EU) 2016/679, Article 17 - the right to erasure, accessed on 2026-11-12
The listings were run on 2026-11-12: the TypeScript with Node 24, the SQL with PostgreSQL 17 on a test database with 200,000 generated rows. The test data is invented; the row count in the last plan is the real one from the run.

Commenti
Caricamento commenti...
Sign in to comment