Skip to content
Shobam

03Full-stack engineer2024

Solar appliance store

A storefront for a shop selling solar appliances — one catalogue, a cart that behaves, and product pages served from cache.

Stack
Next.js · TypeScript · PostgreSQL · Stripe
An abstract plate standing in for the storefront — no internal screen, data or identifier is shown.
An abstraction of the storefront surface, not a capture of the product. No internal data, screens or identifiers are shown.

00The problem

A catalogue is a hard problem wearing a simple costume. Every product page looks like the last one, which is exactly why the whole catalogue becomes one slow query if you build it the obvious way. The shop sold solar appliances — inverters, panels, batteries — where the specification matters more than the photograph, and customers compare before they buy.

01What I owned

The store end to end, from the schema behind the catalogue to the checkout that took the money.

  • The storefront: category, filter, product, and the pages between them.
  • The cart, held server-side so a refresh doesn't lose it.
  • Checkout and payment, including the webhook that confirms it.
  • The caching layer that decides what is stored and what is rebuilt.

02The hard part

The catalogue changes often — prices, stock, new models — and every change meant rebuilding the pages that referenced it. With a product per URL, one edit could touch hundreds of pages at once, and rebuilding them on demand put the slow path exactly where customers would feel it.

The stock rules were the other half of it. A sold item has to disappear from the shop without taking the rest of the catalogue down with it, and the cart has to agree with what the catalogue says.

03What I changed

I moved the rebuild off the request path. Catalogue data is fetched once and cached; the pages that depend on it are generated from that cached shape rather than from a live query. A price or stock change updates the data, and the pages pick it up on the next rebuild instead of the next request.

The cart moved to the server for the same reason: a cart that lives in the browser is a cart that disappears, and a checkout that starts from an empty cart is a checkout that fails.

04What it did

The store carried a catalogue that changed daily without a rebuild per customer. Product pages were served from cache rather than assembled on demand, and the cart survived a refresh, a shared link and a phone that had run out of memory.

05What I'd do differently

I'd have decided the caching policy before writing the catalogue queries, instead of finding out which pages were slow once the shop had real traffic. I'd also have kept the invalidation rules next to the code that changes prices — the two drifted apart, and only one of them was tested.