Skip to content
MSO CloudDocumentation

Edge and loading performance

On this page

Kind: cross-cutting concept. Read this if you are an SRE or front-end engineer and need to know what the edge caches, what it never caches and how page speed is observed.

Up/Down: up: L2 Containers. Where the edge runs: Deployment.

In short#

How requests travel from Vietnam browsers to the distant origin, how compression and caching separate public assets from tenant data, and how dashboards stream initial panel data in one round-trip while field RUM tracks Core Web Vitals. Authoritative record: docs/adr/0064-edge-delivery-and-dashboard-streaming.md.

Edge and origin delivery topology (Vietnam users → distant origin)Vietnam browser45–90 ms to Edge210–230 ms to the originStatic chunks:assets hostWorkspaces:tenant wildcardplatform hostCloudflare Edge (Proxied)HTTP/3 QUIC + regional TLS• assets host → HIT• platform host + tenant wildcard• Unlocked /share/* → 60 s cache• Warm H2 pool to distant originDirect DNS-only exceptions• canonical admin host (2 GiB upload)• the origin host (white-label)Traefik v3 (the origin region)msocloud-response@file:• encodings: [br, gzip]• excludes SSE + woff2• excludes avif/webp/mp4• minBody: 1,024 BVerified IP boundary:X-Real-Ip checked againstCloudflare CIDRs beforereading cf-connecting-ipWeb + Data (< 1 ms)Next.js 16 + tRPC v11• Cookie-free public bypass• Parallel auth & layout• RSC panel prefetch (≤ 6)• Server-Timing + /api/rumCo-located stores:Postgres (FORCE RLS)Redis + Object storeSame Docker bridge (< 1 ms)Latency physics invariantCompute and Postgres stay co-located (< 1 ms per SQL query). Every optimization eliminates extra VN↔origin round-trips instead of splitting web from DB.
Ingress split between Cloudflare edge proxying and DNS-only upload/white-label exceptions, feeding Brotli-first Traefik and co-located web + database services.

Why latency accumulates across continents#

A single HTTP request from Vietnam to a distant origin region pays ~215 ms of propagation delay even when the server computes in 10 ms. Four multipliers turn 215 ms into multi-second page loads:

Multiplier Mechanism Mitigation in place
Handshake trips Direct TCP + TLS 1.3 to the origin adds 2 RTT (~450 ms) on cold connections Cloudflare proxy (orange-cloud) on the platform host, the tenant wildcard, the assets host terminates HTTP/3 QUIC + TLS at regional edge PoPs
Wire bloat gzip HTML is ~53% larger than Brotli; re-compressing woff2 wastes CPU Traefik msocloud-response@file orders encodings: [br, gzip] and excludes pre-compressed fonts, images, video, and text/event-stream
Serial client trips Rendering widget frames only after browser hydration + chunk import adds 2–3 extra 215 ms round-trips Server-side active-tab panel prefetch (HydrationBoundary) + eager preloadWidgetFamilies on mount and tab switch
Sequential DB hops Serial SQL lookups in auth, layout, and page metadata add avoidable origin wait Concurrent users + orgMemberships in auth, hoisted getLauncherTiles inside the layout RLS scope, parallel page setup

Proxy and caching boundaries#

Every route falls into one of four strict caching tiers so performance never compromises tenant isolation or strict CSP:

Surface Example paths Set-Cookie Edge cache policy Why
Hashed static assets assets host/_next/static/* Never public, max-age=31536000, immutable Content-addressed filenames; served from Cloudflare edge (HIT)
Unlocked public shares GET /share/[slug] (signed-out, no password cookie) Never (public-proxy-bypass.ts) public, s-maxage=60, no-transform Explicitly permitted by apps/web/src/lib/share-edge-cache.ts; zero cookies
Anonymous nonced HTML /, /mso, /privacy, /terms, /help/* Never (public-proxy-bypass.ts) private, no-cache, no-store, no-transform Root layout injects a per-request CSP nonce; caching nonced HTML at a shared CDN would replay one nonce across visitors
Authenticated tenant traffic /dashboards/*, /reports/*, /api/trpc/*, /admin/* Session / anchor as required private, no-store Tenant-scoped RLS data; never stored in shared caches

apps/web/src/lib/public-proxy-bypass.ts keeps strictly anonymous public routes and /api/rum / /api/csp-report beacons out of NextAuth(edgeAuthConfig).auth(...). Any request carrying an Auth.js session cookie, the .platform host identity anchor, ADMIN_ORG_COOKIE, ?sso=, or landing on / of a tenant host still runs the full authenticated proxy path.

Single-trip dashboard delivery#

Single-trip dashboard rendering and hydration pipeline1 · Auth & LayoutParallel users + membershipsSingle withOrgContext scopeLauncher tiles hoisted insame RLS transactionInvariant (§72):Zero session process cache2 · Active-Tab Plannerdashboard-prefetch-plan.tsResolves active tab + ?tab=Mirrors DeckViewParams:resetOnLoad, defaults, pv.*Drops ownLegDim per cardCap: ≤ 16 widgets / deck3 · Bounded PrefetchcreateTRPCOptionsProxyConcurrency cap: 6 workersReuses caller AppContextPer-widget errors swalloweddehydrate + SuperJSONRuns beside packChrome4 · Browser HydrateHydrationBoundary seedsQueryClient (stale 60 s)preloadWidgetFamilies()starts chunks on mountand on selectTab() click0 extra tRPC round-tripSafety guards:Prefetch skips whenever activeOrgId/userId is absent, brand switchTo or autoPinBrand is pending, or a card is visibleWhen-gated.Enforced by apps/web/src/__tests__/dashboard-prefetch.test.ts and pnpm run performance:budget (§76 route-specific JS ratchet).
Server-side active-tab panel prefetch runs alongside chrome resolution inside one RSC response and hydrates directly into TanStack Query.

Key modules in this path:

  • apps/web/src/server/dashboard-prefetch-plan.ts — pure planner shared by runtime and unit tests (DASHBOARD_PREFETCH_CONCURRENCY = 6, DASHBOARD_PREFETCH_MAX_WIDGETS = 16).
  • apps/web/src/server/dashboard-prefetch.ts — server-only runner using createTRPCOptionsProxy and SuperJSON.serialize over the request's already-pinned tenant AppContext.
  • apps/web/src/trpc/provider.tsx — pairs hydrate: { deserializeData: SuperJSON.deserialize } with the existing 60-second staleTime.
  • apps/web/src/app/(dashboard)/dashboards/[slug]/_components/dashboard-view.tsx — calls preloadWidgetFamilies(widgetFamiliesOf(...)) for the active tab and on tab switches (selectTab) so widget family chunks load in parallel without waiting for individual FamilySlot mounts.

Observability and regional migration gate#

Performance decisions rely on live production telemetry rather than synthetic guesses:

Signal Source Exposed as Cardinality & privacy rule
Per-stage API latency apps/web/src/app/api/trpc/[trpc]/route.ts Server-Timing: auth;dur=..., rl;dur=..., exec;dur=..., total;dur=... Durations only; never emits tenant slugs or procedure inputs
Field Core Web Vitals apps/web/src/lib/rum-client.ts → POST /api/rum yng_web_rum_lcp_seconds, yng_web_rum_inp_seconds, yng_web_rum_cls, yng_web_rum_ttfb_seconds Paths collapse to 11 fixed templates; share tokens and slugs stripped
Browser bfcache rate pageshow (event.persisted) → POST /api/rum yng_web_rum_bfcache_total{route,persisted} Zero unload listeners attached; lazily loaded during idle time
When to stay on current region + Edge vs move full primary to a nearer regioe / VietnamStay on Track A (origin + Edge)• Dashboard p75 LCP ≤ 2.5 s• Or Server-Timing exec p75 ≥ 250 ms (optimize SQL/JS before moving region)Action:Keep single origin host; scale edge & SSRMove to Track B (nearer region)Trigger only when ALL 3 hold (14 days):1. p75 TTFB > 800 ms or p75 LCP > 2.5 s2. Server-Timing exec p75 < 250 ms3. Active VN org load justifies regionMove Web + Postgres + Redis togetherRejected anti-patterns× Web in a nearer region + Postgres at the origin (adds 1–2 s cross-region SQL latency)× Hyperdrive over attested RLS× Inline 249 KB CSS into HTML× Cache nonced HTML at CDN
Field RUM decision gate and explicitly rejected topologies.

Decisions and gates#

Decision Mechanism Enforcing gate
Brotli-first origin compression and binary exclusions infra/traefik/msocloud-response.yml apps/web/src/__tests__/traefik-response-middleware.test.ts
Cookie-free anonymous public proxy bypass apps/web/src/lib/public-proxy-bypass.ts, apps/web/src/proxy.ts apps/web/src/__tests__/public-proxy-bypass.test.ts, share-public-surface.test.ts
Bounded active-tab server panel prefetch apps/web/src/server/dashboard-prefetch-plan.ts, dashboard-prefetch.ts apps/web/src/__tests__/dashboard-prefetch.test.ts, limits-registry.py
Eager widget family preloading under bundle budget dashboard-view.tsx, widget-family-loaders.generated.tsx pnpm run performance:budget, scripts/audit/performance-boundaries.py
Granular Server-Timing and bounded-cardinality RUM apps/web/src/app/api/trpc/[trpc]/route.ts, apps/web/src/app/api/rum/route.ts apps/web/src/__tests__/rum-beacon.test.ts, scripts/audit/api-body-cap.py

Where it stops#

Covered here: the active delivery path, compression policy, prefetch pipeline, and observability gates. Operator Cloudflare dashboard steps live in the internal tenant domains runbook; numeric ceilings are pinned in Limits and budgets.