Architecture decision record · ADR-0025

The live demos run in the browser

The demos run fully in the browser, with no hosted server. They are pages of the guide under demos/, with a "Demos" section in the guide contents.

Status
Accepted
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
None

Context

Plan section 15 lists five live demos: "Every collection", a 1M-row grid with server group, pivot and live ticks, an infinite feed with two-way load, a collaborative sheet, and a kanban board. The plan put them on a hosted server: the Rails gem on a free or low-cost host, with a data reset each hour, rate limits and a read-only fallback. Open question 6 asks which host and which budget. The maintainer did not give a host or a budget yet.

The guide is a static site on GitHub Pages (joegaudet.com/ember-lattice/guide/). GitHub Pages serves files only. It cannot run a server or a socket, and it cannot set the COOP and COEP headers, so the guide cannot use SharedArrayBuffer.

The demos must show the real Lattice code, not a mock. A demo that shows a server that is not the Lattice server tells the user nothing about Lattice.

Decision drivers

Not recorded in the original ADR.

Options considered

Not recorded in the original ADR.

Decision

  1. The demos run fully in the browser, with no hosted server. They are pages of the guide under demos/, with a "Demos" section in the guide contents.

  2. The server is the real protocol code in a Web Worker. docs-app/workers/row-server.ts takes each request as a message. parseRowsRequest checks the request against the allow-list, and evaluate (the reference implementation, ADR 0005) answers it. A DataSource on the page (worker-source.ts) sends the requests; to a row model it is the same as fetchDataSource over HTTP. An abort sends a cancel, and the server drops a request that did not run yet.

  3. Latency is a floor, not an extra delay. Each answer takes at least 40 to 120 ms, as a network does. A request that takes longer to compute gets no added time.

  4. The 1M-row grid uses an index and a level cache. evaluate reads every row it gets. On 1M rows, one call took 0.6 to 2.5 s in Node 24. The demo server does what a database does:

    • An index on the group columns (region, desk). A request with group keys gets only the rows of its group, not every row. A leaf block of one desk reads about 21k rows.
    • A cache of each group level (shortcut). The worker computes the root level, with and without the pivot, before it says that it is ready. The ticking columns (price, change) are not grouped or aggregated, so a tick does not make a cached level wrong. A demo that ticks a grouped or aggregated column must clear the cache on each tick.
    • Live ticks change a few of the rows that the page got last, and the server sends one transaction for each group route, because ServerRowModel finds the rows by route.
    • A button pauses the ticks (WCAG 2.2.2). The ticking cells are not in a live region.
  5. The collaborative sheet uses the real createDocServer in a SharedWorker. The doc server of @ember-lattice/server runs with IronCalc as its engine and the op log in memory. Every window of the guide on one origin connects to the same SharedWorker, so two windows see the cursors and the formulas of each other. Each window has its own view with IronCalc in a worker, as test-app/app/sheet has. A SharedWorker port sends no close event, so a page sends bye when it goes, and presence also times out.

  6. The fallback is a leader on a BroadcastChannel. A browser with no SharedWorker (Chrome on Android) uses the Web Locks API to choose one leader page. The leader runs the same doc server in a dedicated worker, and every page talks to it on a BroadcastChannel. When the leader goes, the next page gets the lock. It starts a new server from its own copy of the doc, and every page joins again and gets a snapshot.

  7. A hosted Rails demo server stays a later option. It needs a host and a budget from the maintainer (open question 6). The demos do not depend on it.

  8. The worker code is in docs-app/workers/, outside app/. The app build puts every module of app/ in the page bundle. A worker file in app/ ran on the page and pulled the doc server and kysely into the main chunk. So the Template tab of a demo shows the page code, and the "How it works" section shows the server code.

Consequences

  • The demos cost nothing to host, have no rate limits and no data reset, and work offline.
  • The data is per browser. Two users on two computers do not see each other. Only windows of one browser on one origin share the collaborative sheet.
  • The 1M-row demo makes its rows in the worker, so the page holds only the blocks in view. The first level takes about 1 to 2 s on a laptop, in the worker. The page thread has no long task.
  • The demo server is not a product. It is demo code in the guide, and evaluate stays the reference, not a fast engine.

Hooks in the packages

The demos use two small hooks, so they have no copy of package code:

  • @ember-lattice/collab exports toDoc(book): the CollabDoc of a Workbook. The fallback leader starts its new server from it.
  • @ember-lattice/server has a ./collab subpath export. It has the doc server and no SQL, so the collab worker bundles have no kysely.

Confirmation

Not recorded in the original ADR.

Interview record

Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.

QuestionAnswerSource
Where does the text of this page come from?From the Markdown file docs/adr/0025-demos-in-the-browser.md at commit 4c77ac4. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so.Document: docs/adr/0025-demos-in-the-browser.md

Changelog

DateAuthorChange
2026-12-02Joe GaudetStatus in the Markdown file: accepted, 2026-12-02.
2026-12-03Joe GaudetCommit 7ce4af2: Lattice 1.0 (#1)
2026-12-04Joe Gaudet (agent)Converted from docs/adr/0025-demos-in-the-browser.md to this page. The text is the text of the Markdown file.

The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.