TL;DR
- So, what numbers does yours deliver? Time per hotel and searches per second per core are easy to measure on any booking engine. This article shows exactly how I measured mine, so you can compare.
- This engine keeps everything a search needs in the memory of the process that answers it. No network, no database, no locks on the hot path. Updates arrive as events and swap immutable snapshots atomically.
- With a complete contract model (rate plans, three pricing modes, offers, packages, markups, restrictions), one core of an Apple M3 Max evaluates a hotel in 0.4 to 0.6 µs (100 and 1,000 hotels) and answers 1,664 searches per second on a 1,000-hotel destination.
- Without locks the search scales with cores: one laptop answers 2.5 million searches per second on a 10-hotel destination using its 10 performance cores (85 % of perfect scaling), and about 15,000 per second on a 1,000-hotel one. Behind a mutex, the same engine on the same 10 cores answers 222,000.
- A Raspberry Pi 1 from 2012 (one 700 MHz core, 512 MB) evaluates a hotel in about 76 µs and serves a 100-hotel destination at ~130 searches per second, on its single core.
- The search allocates zero bytes and keeps answering while it absorbs 100,000 inventory updates per second (a quick run on a 100-hotel destination).
- Over HTTP, with one worker thread, a laptop serves 8,000 searches per second on a 100-hotel destination with p99 under 3 ms (preliminary). Architecture beats hardware. Everything is open source and reproducible.
How to build a first-class booking engine
For 25 years I have built booking engines for tour operators, bed banks and travel agencies. This article shares how to build a first-class one: fast, complete and simple to run. The secret fits in two words: eliminate contention.
Booking systems are often built as fleets of services, caches and databases, and they end up spending most of their time waiting for each other. Buying more hardware does not fix that. Removing the waiting does. To make the point with a bit of humour, I ran the engine on the most modest computer I could find in a drawer: a Raspberry Pi from 2012, with one 700 MHz core and 512 MB of memory. It still answers in microseconds per hotel, with a contract model as complete as real ones, a level of performance that systems running on incomparably more hardware often do not reach.
Everything is built and measured in the open: the engine and its model, a backoffice to edit contracts, events that keep searches up to date, test bookings that take real locks, a public demo, and the same engine in Go, Rust and C. The article goes through it in order: the idea, the engine, how it was measured, what speed cost in readability, how changes and bookings travel, what the public demo taught me, scaling out, other languages, and when not to do any of this.
The thesis: eliminate contention
Availability search is slow for one reason: it waits. It waits for the network, for the database, for a cache, for a lock, for a supplier. The arithmetic itself is cheap.
The principle is simple. Put everything a search needs in the memory of the process that answers it, and never make the search wait for anyone.
In practice that means four rules:
- No network and no database on the read path. The read model lives in the same JVM that serves the request.
- No locks on the hot path. Readers take one volatile read of an immutable catalog and then only walk arrays.
- No allocation per search. Buffers belong to the caller and are reused; the garbage collector has nothing to do.
- Cheap discards first, prices last. Dates, stop sales, occupancy, inventory, restrictions, and only then money.
The price is paid elsewhere: memory, eventual consistency in the search, and a write side that must revalidate. This article measures both the gain and the price.
Architecture: CQRS taken to the extreme

the whole system · read side in memory, write side in Postgres, Kafka in between
The write side owns the truth. Contracts live in Postgres as periods ("from 1 to 30 June, the double on half board costs 120"), edited in a backoffice; bookings, held and sold rooms live there too. Every change writes its event in the same transaction, and a relay publishes it to Kafka: a whole hotel snapshot when a contract is published, a small inventory event when a room is held, sold or released. Each search node keeps an immutable catalog of snapshots in memory and swaps it atomically when an event arrives; a search reads the catalog reference once and then only walks arrays. The website is static and talks to the nodes for searches and to the write side for bookings, which never trust the search: they price and lock again against the source of truth.
A complete contract model, or the numbers mean nothing
A first, deliberately small model proved the mechanics in a few hours, and it was too easy: fast numbers on a toy model prove nothing. So the engine implements a contract model as complete as the ones I have built in production, cross-checked against the public API specification of a widely used hotel PMS:
| Area | What the engine models |
|---|---|
| Rate plans | 2 to 4 per hotel: flexible, non-refundable, wholesale net, resident market. Channels, markets and a sell window per plan; derived plans ("NRF = FLEX − 10 %") resolved at projection time |
| Pricing | Three modes: per room (extra adult, children by band), per person (single use, 3rd adult, child by position and band, infants) and occupancy tables (1 to 5 adults, extra adult, children by band) |
| Restrictions | Per plan × room × day: closed, closed for a channel, closed to arrival and departure, min/max length of stay on arrival and through, lengths not available, min and max advance |
| Inventory | Shared by all plans of a room type: allotment, free sale, on request, hotel and room stop sales; several identical rooms per request |
| Offers | Early booking, long stay, last minute, free nights (stay 7 pay 6, repeatable, cheapest nights free), fixed amounts; booking and travel windows applied per night; combinable offers cascade, non-combinable ones compete |
| Commercial | Net plans with a markup per plan and channel; commissionable retail plans; tourist tax; cancellation tiers |
How the pieces fit together: a tariff (rate plan, seasons, prices and its conditions) belongs to one hotel and is edited as a unit, while inventory, offers and supplements are shared by every tariff of the hotel.

the write model, docs/design/model-v2.md · a tariff is what the backoffice edits and publishes as one unit
The synthetic generator produces 1,660 hotels with these features and realistic seasonality. It is calibrated so that 62 to 74 % of hotels have availability for a typical search, so discards are realistic too.
How one search runs
A search returns the cheapest option (rate plan, room, board, total) of every available hotel in a destination. For each hotel:
- Hotel checks: stay inside the loaded horizon, no hotel stop sales on any night (a bitset range test).
- Rooms, once for every plan: occupancy rules, then shared inventory over the nights.
- Plans, cheapest first: channel, market and sell window.
- Lower bounds before any price. For each board, the cheapest possible price of the stay is precomputed per 28-day block. If even that, with the best offer and the markup applied, cannot beat the winner so far, the option is skipped. Only 18 % of boards survive this test.
- Restrictions for the surviving plan and room, one dictionary lookup per night.
- Prices, night by night: one weighted sum of the tariff slots, read from a small per-plan table.
- Offers only for candidates that can still win; packages and markup; keep the cheapest, ties broken by catalog order.
Three details carry most of the weight:
- Zero allocation. Request, result and scratch buffers belong to the caller and are reused. A unit test asserts 0 bytes per search with every feature in play.
- Exact money. Cents in
int, totals inlong, accumulation in 10⁻⁴ cent, one rounding at the end. Nodoubleanywhere near a price. - Correctness under pruning. A brute-force test values every plan, room and board of real synthetic hotels and checks that the pruned search returns exactly the same option, over 2,000 comparisons.
Method and machines
All in-process numbers come from JMH: forked JVMs, warm-up, sampled latency percentiles, a GC profiler. Requests come from a reproducible mix: arrival dates across the year, a leisure booking curve (20 % within a week, 20 % beyond three months), four sales channels, 30 % domestic market and 10 % two-room bookings. One search evaluates every hotel of the destination.
| Machine | CPU | Cores used | Memory | JVM |
|---|---|---|---|---|
| Laptop | Apple M3 Max | 1 to 10 performance cores | 36 GB | Corretto 26, C2 |
| Cloud | Hetzner cx23, AMD EPYC-Rome, 2 shared vCPUs, dedicated node (the same instance type sometimes gets an Intel Skylake; see below) | 1 to 2 | 4 GB (2 GiB for the benchmark pod) | Temurin 25 LTS, C2 |
| Raspberry Pi 1 Model B (2012) | ARMv6, one core at 700 MHz, no L2 for the CPU | 1 | 512 MB (426 usable) | Zulu 11, client VM, C1 only |
The Pi needs a Java 11 build, the newest JDK for ARMv6; the engine code is the same.
The test machine: a Raspberry Pi 1 Model B from 2012. One 700 MHz ARM core, 512 MB of RAM, no L2 cache for the CPU.
The back of the board. The whole system, operating system, JVM and the engine, boots from a microSD card.
Raw results, the JMH JSON and a dated journal of every run, including the failed ones, are in the repository.
Results: time per hotel and searches per second

JMH, docs/results/JOURNAL.md · all three machines with the optimised engine, 100-hotel destination
Time per hotel is the fair unit across systems: a search over a bigger destination simply evaluates more hotels. Searches per second per core, the unit users feel, depend on destination size:
| Destination | Apple M3 Max | Hetzner cx23 (AMD EPYC, shared vCPU) | Raspberry Pi 1 |
|---|---|---|---|
| 10 hotels | 298,000/s (3.4 µs) | 133,000/s (7.5 µs) | 946/s (1.06 ms) |
| 100 hotels | 24,900/s (40 µs) | 12,300/s (81 µs) | 131/s (7.6 ms) |
| 1,000 hotels | 1,664/s (0.60 ms) | 537/s (1.9 ms) | 9/s (108 ms), with 512 MB barely enough |
The same optimisation gave ×2.4 to ×2.8 on the M3, ×1.9 to ×2.4 on the cloud server (measured before and after on the same node), but only ×1.3 to ×1.4 on the Pi, whose JVM has only the C1 compiler and whose CPU has no L2 cache. The Pi gains less from cleverness, and still stays well under 200 µs per hotel.
Scaling with cores: what a lock costs

JMH throughput, docs/results/phase3/scaling-t-article-local-m3max-v2opt.json.gz · optimised engine, 10-hotel destination, 7 nights, 2 adults*
The same engine behind three access disciplines. Without locks, 10 threads deliver 85 % of perfect scaling: 2.5 million searches per second on a 10-hotel destination. A read-write lock costs about 9 % at 10 threads: a search now lasts only 3.4 µs, short enough for readers to start meeting on the lock's shared counter. A mutex is worse than useless. It serialises everything, and handing the lock from thread to thread costs more than the search itself, so 10 threads together deliver 222,000 searches per second, fewer than one thread alone. On a 1,000-hotel destination a search lasts 600 µs and a read-write lock costs nothing measurable (both about 15,000 searches per second with 10 threads), while the mutex stays at a few thousand.
Memory, and the cache wall
The complete model is also compact: about 54 KB per hotel for a year of contracts. Contracts price by season and weekday, not by day, so each plan × room × day stores a 2-byte index into a small table of distinct prices, and restrictions work the same way. A 1,000-hotel destination is about 54 MB; 50,000 hotels fit in 2.7 GB. (Measured on the snapshot model; a running node holds about 64 KB of heap per hotel.)

JMH, docs/results/JOURNAL.md · optimised engine on both machines
The cost per hotel rises only slightly from 10 to 100 hotels, because the whole destination sits in the CPU caches. At 1,000 hotels (54 MB) it no longer fits and every search waits on main memory: from 100 to 1,000 hotels the cost per hotel rises 50 % on the laptop, whose large caches still hold part of it, and 2.3 times on the cloud server. Put together, a search over 1,000 hotels takes 15 times as long as one over 100 on the laptop (601 µs against 40 µs): ten times as many hotels to evaluate, each about 50 % more expensive because it now comes from main memory. The logic is the same; every hotel gets the same checks and the same pricing, there are simply ten times as many of them. I expected sharding to bring every node back into the cached regime. The measurement below says it does not, and why.
How much readability is a microsecond worth?
The first complete version answered the 1,000-hotel destination at about 670 searches per second per core, below the 1,000 target. Profiling showed no garbage collection at all: about half the time went into pricing nights, a fifth into restriction checks. The fixes fall into two families, and they do not cost the same to maintain.
| Change | Gain | Maintenance cost |
|---|---|---|
| A1. Packed layout: each hotel's data in a few flat arrays addressed by offsets, contract apart from inventory | ×1.3 to ×1.5, together with A2 | High: a wrong offset is a silent wrong price. Kept behind accessors and guarded by golden tests |
| A2. Loop details: tariff offsets read once per plan and room, specialised slot loop, range checks on bitsets | ×1.3 to ×1.5, together with A1 | Low: local, readable changes |
| B. Lower-bound pruning and cheapest-first order | ×1.6 to ×1.9 on top of A (2 adults; less with children) | Medium: a correctness argument that must survive model changes, guarded by the brute-force test |
Together they made the search 2.4 to 2.8 times faster: the 1,000-hotel destination went from 1,497 µs (about 670 searches per second) to 601 µs (1,664 searches per second per core).
The lesson: doing less work (B) paid as much as doing the same work faster (A), with far less damage to the code. The packed layout is the change to justify; it pays mostly when data does not fit in the CPU cache, and because it makes inventory updates cheap.
What the packed layout looks like. Contracts price by season, not by day, so a day stores two small indexes into dictionaries of distinct price rows and restriction sets. Inventory lives in separate arrays, so an allotment change copies about 6 KB and shares the rest of the hotel.

HotelSnapshot, engine-core · values are illustrative
A confession belongs here too. Two of my measurements showed "no improvement" and were wrong: the shaded benchmark jar still contained the old classes, so I compared the old code with itself. Checking the bytes inside the jar caught it. Verify what you measure before you believe it.
Searching while the contracts change
A booking engine is never read-only: bookings consume allotment, revenue managers close dates, contracts get republished. Readers must not notice.
Updates never touch a snapshot in place. A writer builds a new snapshot of the one hotel that changed, sharing every array that did not change, and swaps the catalog reference atomically. A search that started before the swap finishes on the old data; the next one sees the new.
Because contract and inventory live in separate arrays, a booking or an allotment edit copies only that hotel's inventory:
| Update on the search node (1,000-hotel catalog, 2 destinations of 500) | Time | Memory allocated |
|---|---|---|
| Allotment change (booking, edit) | 0.77 µs | 12 KB |
| Inventory event decoded from the wire | 0.66 µs | 13.5 KB |
| Whole contract published (binary snapshot decoded) | 3.0 µs | 63 KB |
One writer thread can absorb about 1.5 million inventory changes per second. In a quick run with a writer applying 100,000 allotment changes per second, far above any real booking rate, readers kept going: mean search latency rose 12 to 14 % and p99 barely moved. With G1 the extreme tail (p99.99) grew about five times from the writer's garbage; ZGC kept it flat on a 100-hotel destination, though not entirely on a 1,000-hotel one.
One finding had to be fixed before large nodes: every swap copied the catalog's whole array of hotel references, so the cost of a single allotment change grew with the catalog. The catalog is now split into one immutable chunk per destination, and a change copies only its destination's chunk plus a small array of chunk references:
| Catalog | Allotment change before | After |
|---|---|---|
| 1,000 hotels | 0.89 µs, 18 KB copied | 0.77 µs, 12 KB |
| 5,000 hotels | 2.69 µs, 66 KB | 1.19 µs, 12 KB |
| 20,000 hotels | 7.44 µs, 246 KB | 1.05 µs, 12 KB |
The cost of an update no longer depends on how many hotels the node holds, and searches did not get slower: they were already reading one destination at a time.
From the backoffice to the search: events end to end
The write side, as a contracting team sees it
Contracts are edited in a backoffice built with Mateu, a framework I maintain for this kind of screen, on Spring Boot and Postgres. It is deliberately not a set of CRUDs over tables: a tariff is edited as one unit, with its seasons, the price of every room and board per season, occupancy supplements, mandatory supplements, restrictions, cancellation and markups, and an inventory calendar shows allotment, sales modes and stop sales day by day.
The tariff editor of the demo backoffice. Prices are typed straight into the matrix, one column per season; an empty cell means not for sale.
A tariff is saved as a draft until it is published, and the search never sees a draft. Validating builds exactly the binary snapshot the search nodes will load, then rolls the transaction back; publishing does the same and commits. So a contract the engine would reject never gets published, and the projection from periods to arrays is tested by every single publication. A test checks the other direction too: republishing an unchanged tariff produces a byte-identical snapshot.
How a change reaches the search nodes
In-process swaps are only useful if changes reach the search nodes. The write side does it with a transactional outbox: when a tariff is published or an allotment changes in the backoffice, the same database transaction projects the hotel and stores the binary snapshot, or just its inventory, in an outbox table. A relay sends committed rows to Kafka: one compacted topic for snapshots and one for inventory, keyed by hotel. A search node reads both topics from the beginning before it accepts traffic, then applies each batch of events with a single atomic swap on one feed thread. Searches stay lock-free.
| Change | Size on the wire | Commit to visible, p50 | p99 |
|---|---|---|---|
| Allotment change (inventory event) | 7 KB | 3.4 ms | 15.7 ms |
| Published tariff (whole hotel snapshot) | ~60 KB | 19.7 ms | 26.6 ms |
Measured on the laptop with Kafka and Postgres in Docker, 160 hotels. Most of the snapshot time is Docker Desktop's port forwarding for messages over 16 KB; inside the Docker network the same message takes about 1 ms. The search node never waits for any of it: a search running during a swap simply finishes on the catalog it started with.
Each piece is there for a reason:
- Outbox, not a dual write. Writing to Postgres and then to Kafka can fail between the two. The event is stored in the same transaction as the contract, and a relay sends it after the commit, so a change is never lost or sent without being saved.
- Compacted topics. Kafka keeps the latest snapshot and inventory of every hotel, so a new search node starts by reading the topics, without touching the database. Scaling out is starting another node.
- Versions per hotel. Every event carries the hotel's version; a node ignores anything older or repeated, so redeliveries and reordering are harmless.
- Nothing on the search path. None of this runs inside a search: the feed thread builds the new catalog aside and swaps one reference.
How a search node starts
A node keeps nothing on disk. Every start, it rebuilds its catalog from Kafka and only then accepts traffic:
- Load. It reads both compacted topics up to the end offsets they had when it started and builds the catalog. An inventory event that arrives before its hotel's snapshot is parked until the snapshot shows up. On the public demo: 1,660 hotels in 8.1 s.
- Warm up. It runs a few seconds of synthetic searches (about 2,500 searches in 5 s on the demo) so the JIT compiler has optimised the search before the first real user arrives.
- Open. Only then does it listen on its port, and Kubernetes sends it no traffic until its readiness check answers.
- Follow. From then on, one feed thread applies new events as they come, swapping the catalog atomically.
There are no offsets to commit and no local state to corrupt: a restarted node, a new replica and a new shard all start the same way, ready for traffic in about 15 seconds including the warm-up, without asking the database for anything.
Doesn't a node need every event since the beginning of time? No, by design: both topics are compacted by hotel, so Kafka keeps only the latest record of each one, and an inventory event carries the hotel's whole inventory rather than a delta, so the latest one is all a node needs. Bootstrap grows with the number of hotels, not with history. One trap to avoid: Kafka never compacts the segment it is writing to, and by default that segment only closes at 1 GB or after seven days, so a busy system would still make new nodes read a week of changes. Rolling segments every hour and letting the cleaner run early keeps it to about one record per hotel plus at most an hour of changes.
The real cost of a start is bytes, not events: about 60 KB of snapshot per hotel, so about 100 MB for the demo's 1,660 hotels and about 3 GB for 50,000. The topics are partitioned by destination, so each shard reads only the partitions of the destinations it serves.
Booking: where the locks belong
Search can be slightly stale; selling a room cannot. So booking lives entirely on the write side, and it is the one place in the system that takes locks. Every booking in the demo is a test booking: fictional hotels, references starting with TEST-, no payment fields, nothing reserved and nothing charged, and every response says so.
- Pre-booking takes the
rateIdthe search returned and prices it again with the same engine, but on a snapshot built from Postgres at the hotel's current version. If the price changed since the search, the client is told. Then, in one transaction, it locks the hotel's inventory rows night by night, in a fixed order so that two bookings can never deadlock, checkssold + held + requested ≤ allotmentfor every night, creates a 15-minute hold, and writes the inventory event to the outbox. - Booking starts a saga in EventConductor, a workflow engine I maintain: confirm the hold, charge (simulated), store the confirmation. If a step fails, the compensation releases the rooms. Expired holds are released by a timer.
- Cancellation applies the contract's cancellation tiers and releases the rooms.
| Measured on the laptop | Result |
|---|---|
| 50 threads competing for the last 5 rooms | exactly 5 succeed, 45 are refused, in 3 runs out of 3 |
| Pre-booking, one client | 3.9 ms median, 6.1 ms p99 |
| Pre-booking, 50 concurrent clients | 230 holds per second, 85 ms median |
| Searches on the search node | 70,000 per second, 0.64 ms median (same 50 clients, separate run, 10-hotel destination) |
| From the hold's commit until the room disappears from search results | 1.2 ms median, 2.8 ms p99 |
The contrast is the point of the whole design. A pre-booking costs milliseconds and a few hundred per second, because it must be right: it takes locks and talks to a database. A search costs microseconds and runs by the tens of thousands, because it never waits for either. The only contention left in the system is the contention that buys correctness.
End to end over HTTP (preliminary)
The HTTP API is not invented for the demo: it follows easytravelapi, an open specification for travel booking APIs that I maintain, and this engine is the reference implementation of its version 2 draft. Among other things it uses money as integer cents, never floating point; a rateId that carries everything needed to price the option again; results paged cheapest first; and an immediate 503 when a node is saturated.
In-process numbers are only half the story, so here is a first end-to-end figure. The search node runs on the JDK's built-in HTTP server with one worker thread, and a load generator (vegeta) sends requests at a constant rate, so a slow response cannot hide the requests queued behind it. Requests vary dates, stay lengths, occupancies, channels and markets. Responses are the 50 cheapest hotels of the destination, about 22 KB of JSON, while every hotel is still evaluated.
| Destination | Offered load | Served | p50 | p99 |
|---|---|---|---|---|
| 100 hotels | 8,000 req/s | 100 % | 0.38 ms | 2.9 ms |
| 100 hotels | 12,000 req/s | 10,700 req/s, the rest refused with 503 | 11 ms | 27 ms |
| 1,000 hotels | 1,000 req/s | 100 % | 1.7 ms | 25 ms |
| 1,000 hotels | 3,000 req/s | 1,130 req/s, the rest refused with 503 | — | 129 ms |
Two lessons came from breaking it first:
- Page the response. Returning all ~700 available hotels of a big destination (200 KB of JSON) could not keep up with 1,000 req/s. No website shows them all; a page of 20 to 50 is what users see.
- Bound the queue. At 6,000 req/s the server's unbounded queue grew until the heap ran out and the node died. With a bounded queue and an immediate 503 when it is full, the node now absorbs three times its capacity, keeps serving at its limit, and recovers on its own.
Caveat: one worker thread is not one core. The dispatcher thread, the garbage collector, the network stack and the load generator share the laptop.
Why a lone search on the live demo is slower than the benchmark
The public demo reports the compute time of every search, and at first it looked several times slower than the benchmarks. Explaining it took some probing, and both causes are worth knowing before you compare numbers:
- Same instance type, different CPU. The cloud server behind the benchmarks happened to get an AMD EPYC; the demo's node got an Intel Skylake, about half as fast for this code. JMH on the demo's own node gives 179 µs for 100 hotels, not 81.
- Cold caches. A benchmark runs searches back to back, so the destination stays in the CPU caches. A visitor's search arrives alone, on a shared virtual CPU whose caches the rest of the host has just filled with other work. Timing only the search, in process, with no HTTP:
| Pause between searches | 100 hotels | 1,000 hotels |
|---|---|---|
| none (back to back) | 176 µs | 3.3 ms |
| 200 ms | 740 µs | 6.4 ms |
| 2 s | 798 µs | 7.3 ms |
So the engine on the demo is exactly as fast as the benchmark says for that CPU; what a lone request pays is getting its data back into the cache. A node under real traffic sits in the first row. The demo's performance page now shows both figures: the first search, and the median of the same search repeated right after it.
The same probe answers the question "why not gRPC?". On the demo node, writing the JSON of a 20-hotel page takes 76 to 100 µs: 6 % of a request on a 100-hotel destination and under 2 % on a 1,000-hotel one. Most of the rest is the search and the HTTP server and kernel sending the bytes, which a binary protocol would not remove.
Scaling out: sharding by destination
A search is always about one destination, so destinations are the natural shard key: each node loads only its own, a router sends each request to the node that holds that destination, and no search ever needs answers from two nodes. A node reads only the Kafka partitions of its destinations (shards are aligned to partitions) and drops the few foreign events in them, and a new node bootstraps from the compacted topics without touching the database: the public demo's node loads its 1,660 hotels from Kafka in about 8 seconds.
Measured on the cloud cluster with a larger catalog (12,600 hotels in 72 destinations, about 800 MB, one node per machine, load at a constant rate from a separate machine):
| Nodes | Searches served per second | Through an nginx router |
|---|---|---|
| 1 (whole catalog) | 1,311 | 1,339 |
| 2 (half each) | 2,780 | 2,782 |
| 3 (a third each) | 3,803 | 3,917 |
Capacity grows linearly with nodes, and the router costs about 0.7 ms per request. A small Java router written for the test topped out at about 3,500 requests per second on its two vCPUs; nginx was not the limit.
What sharding did not do is make each search faster. I expected a node holding a smaller share to stay in the cached regime, and over HTTP it did not: a node holding the whole catalog and a node holding 1/24 of it both cost 7 to 8.5 µs per hotel. The reason is the same as on the demo: at moderate load, each request arrives after a pause during which the rest of the machine evicts the data from the caches. Searching back to back in process, a cached destination costs 1.5 µs per hotel and roaming over the whole catalog 3.4: the cache effect is real, but "fits" means a few megabytes, one or two destinations, not a fraction of a large catalog. Shard for capacity and for memory; do not count on it for latency.
What if it were not Java?
Is Java the secret, or the obstacle? To find out, the search was ported to Go, Rust and C: the same packed arrays, the same pruning, the same integer money and tie-breaks. A golden test makes the comparison honest. Java exports a catalog and 1,043 requests (900 from the benchmark mix plus edge cases written to break the ports), and every port must return exactly the Java results, line by line. All three do, and all three allocate nothing per search.
Latency per search on one core of the laptop, on the golden catalog and requests the ports are tested against (not the benchmark mix of the tables above, hence slightly different Java figures), 7 nights, 2 adults:
| Destination | Java (JMH) | Go | Rust | C |
|---|---|---|---|---|
| 10 hotels | 3.4 µs | 3.5 µs | 2.4 µs | 2.2 µs |
| 100 hotels | 34 µs | 35 µs | 24 µs | 24 µs |
| 1,000 hotels | 621 µs | 575 µs | 425 µs | 455 µs |
| Searches per second, 1,000 hotels | 1,611 | 1,740 | 2,353 | 2,198 |
| Lines in the hot path | 686 | 625 | 628 | 648 |
Go matches Java. Rust and C are about 1.4 times faster: no bounds checks they can prove unnecessary, tighter loops, a little more control over layout. Over HTTP the differences shrink further, because a node spends much of its time in the network stack and in writing JSON; on quick runs the C node saturated at about 15,000 requests per second on a 100-hotel destination, Go at 12,800 and Java at 10,700, and all of them at about 1,000 on a 1,000-hotel destination, where the search dominates.
The interesting part is what each language made easy or hard:
- Go was the shortest path from Java: a line-by-line port, standard library only, zero allocations checked by its own test tooling. Integer semantics have to be spelled out, and its inliner gives up sooner than Java's C2.
- Rust gave the best speed with no
unsafecode at all, and it compiles to WebAssembly: the in-browser demo is this port, 657 KB gzipped with a 100-hotel destination. - C reads about as well as Java in the hot path; the cost is everywhere around it. Memory safety becomes a proof at decode time (every field the search reads needs a check in the decoder, and forgetting one is silent corruption), signed overflow had to be bounded by hand, and the garbage collector's job, knowing when an old catalog is no longer read, became an epoch scheme that needs sanitizers and stress tests.
The language is worth a factor of about 1.4. The architecture is worth orders of magnitude: every port answers in microseconds for the same reason the Java one does.
When this does not apply
None of this is free, and it is not for every booking problem.
- Memory. About 54 KB per hotel for a year of contracts with 2 to 4 rate plans: 54 MB for 1,000 hotels, 2.7 GB for 50,000. Fine for a chain or a bed bank partitioned by destination; a global catalogue needs sharding.
- The search may be slightly stale. It sees the last snapshot swapped in, usually milliseconds old. Pre-booking and booking must revalidate against the source of truth, which keeps strong consistency.
- Your own inventory only. The model assumes contracts you load. If a search must call third-party suppliers in real time, those calls dominate the latency and this design only removes your share of it.
- The write side gets more work. Projections, versioned events and a binary snapshot format are real code to maintain, and the packed layout is not code everyone can change safely.
- Combinatorics grow memory. More rate plans, markets or per-agency prices multiply the read model; dictionary encoding absorbs seasonal prices, not daily dynamic pricing at scale.
How this was built
Before AI tools, the booking engines I built already priced a hotel in about 90 µs, measured on this same laptop. Six months ago I asked the AI models of the time to improve on that, and none of them managed to.
This time the code was written by an AI, Claude, from Anthropic. I set the goal and the constraints, reviewed every design before it was built, and asked for everything to be measured and written down, failed attempts included. Claude wrote the engine, the backoffice, the event pipeline, the bookings, the ports to Go, Rust and C, the demo and the benchmarks, and it did it very well. The journal in the repository records how it went, step by step, mistakes included.

My earlier engines: my own measurement on the same Apple M3 Max laptop, before AI tools · this engine: JMH, docs/results/JOURNAL.md, 100-hotel destination, 7 nights, 2 adults
What I take away from it
- Contention, not computation, is what costs. Take the network, the database and the locks off the search path and a single 700 MHz core from 2012 answers 130 searches a second with a complete contract model; a laptop core evaluates a hotel in 0.4 µs on a 100-hotel destination, and the whole laptop answers 2.5 million searches per second on a small one.
- Do less work before doing the same work faster. Pruning gave as much speed as packing the data, at a fraction of the cost in readability.
- Put the locks where correctness needs them, and only there. Bookings lock rows and take milliseconds; searches lock nothing and take microseconds, and a held room leaves the search results about a millisecond later.
- Measure, and distrust your measurements. A stale benchmark jar, a different CPU behind the same cloud instance type and cold caches on an idle server each told a story that was not true until it was checked.
- Shard for capacity, not for latency. More nodes scaled throughput linearly; they did not make a lone search faster.
- The language is a detail. Go, Rust and C return exactly the Java results; the fastest is about 1.4 times faster than Java, while removing contention is worth orders of magnitude in any of them.
This article is about hotel availability, but the recipe is not. It fits any business where answers are computed from rules that change slowly, reads vastly outnumber writes, and the data fits in memory or can be split so that it does: airline fares and seats, car rental, event tickets, insurance quotes, freight rates, product prices and stock. Keep the source of truth where it is, project it into immutable snapshots, push changes as events, answer reads in memory without waiting for anyone, and take locks only when something is actually sold.
None of this is exotic: immutable snapshots, events, flat arrays, a transaction and a few locks. The hard part is deciding that the search will never wait, and then keeping that promise in every layer, from the data layout to the HTTP queue.
So: what numbers does yours deliver?
Check it yourself
Every number here can be checked, three ways:
- In your browser, with no server: zcbe-demo.netlify.app/try-in-your-browser loads the Rust port compiled to WebAssembly with a 100-hotel destination (657 KB) and times searches on your own CPU.
- Against a live node: zcbe-demo.netlify.app is a demo hotel website searching a Java node with 1,660 hotels on one shared cloud core; its performance page shows the server-side time of every search. The site is static (built with Astro): Netlify serves prebuilt pages and only forwards
/api/*to the node, so there is no application server between the browser and the engine. It is a demo, rate-limited, not a benchmark. - On your machine: the repository has the engine, the backoffice, the Go, Rust and C ports, the benchmarks, and a journal of every measurement, failed attempts and mistakes included.




