Amir Sorayaei

A 4MB bundle and 400 restaurants

A digital menu a diner opens at the table has one job, and it has to do it before they put the phone down. Ours took about two seconds and shipped four megabytes to do it.

What was there before

I built Top Menu's frontend from zero and kept primary ownership of it. It went on to serve more than 400 restaurants on renewable annual subscriptions, with real ordering and real support.

As it grew, the whole application shipped as one bundle of roughly 4MB, and the initial load sat at about two seconds. The person waiting is standing in a restaurant holding their own phone on somebody else's wifi.

Server data lived in Redux with Redux Persist and a cache I maintained by hand. The same data got fetched again in different places because it was easier than working out whether it was already there.

What I owned

  • The frontend from the first commit through four-plus years in production.

  • Weekly sprint review and planning for a rotating team of 4 to 5 developers, translating what the CEO and the customers wanted into scoped work.

  • Recruiting, onboarding, and reviewing developers until they could work in the system independently.

  • Talking to the restaurant customers directly, which is where the next piece of work usually came from.

I built and owned Top Menu's frontend. The team's work was theirs; my part was the architecture, the review, and deciding what got built next. I also advocated for bringing in dedicated DevOps ownership rather than doing it myself.

What I decided, and what I ruled out

Split the bundle at the route level and load chunks lazily.

Instead of Optimising inside the existing single bundle, or blaming the network.

A diner opening a menu needs one route. Shipping them the admin screens, the ordering flow, and every other page first is the actual cost, and no amount of tuning inside a 4MB bundle fixes shipping 4MB.

Move server data to React Query with SSR-backed requests, and take Redux out of it entirely.

Instead of Keeping Redux Persist and improving the manual cache.

The cache I was maintaining by hand was a worse version of something that already exists and is well tested. Server state has its own rules: it goes stale, it refetches, it belongs to the server. Client state does not.

Keep Zustand, but only for the client state that needed it.

Instead of Moving everything into one store because one store is tidy.

Once the server data was out, what remained was small. A large global store for a small amount of genuinely global state is just the old problem with a new library.

How it works

  1. Diner

    Scans the code

    At the table, on their own phone

  2. App

    Loads one route

    Route chunk, not the whole application

  3. Diner

    Reads the menu

    The thing they came for

  4. Diner

    Orders

    Real orders, not a demo

  5. Restaurant

    Receives and manages

    Admin side, its own chunk

What a diner actually touches. Everything to the right of the scan is what the route split protects.

What went wrong first

I wanted to claim the React Query migration cut our API requests by half, because it obviously reduced them. I could not show it. The measurement was never set up before the change, so the number would have been a guess wearing a percentage sign.

Kept the claims to what was actually measured: the bundle size and the initial load, both of which were observed directly in the build output and in Chrome DevTools before and after.

Confirmed by Chrome DevTools Network and the build output for the bundle, Lighthouse and GTmetrix for the load. The request reduction stays an unmeasured improvement, which is why it is not a number anywhere on this site.

What changed

  • Cut initial load from about 2 seconds to under 1 second by splitting a 4MB bundle into route-level chunks.

    Chrome DevTools Network, Lighthouse, GTmetrix Approximate

  • Built Top Menu's frontend from zero and kept primary ownership of it, through real ordering workflows and renewable annual subscriptions.

    Confirmed

  • Served more than 400 restaurant customers.

    Approximate

  • Handled more than 500K monthly menu visits, deduplicated per user per day.

    Confirmed

    Menu visits, not registered users.

  • Guided a rotating team of 4 to 5 developers.

    Confirmed