Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
86

Frontend System Design · Lesson 86 of 86 · 5 min

Experiment Data Collection and Analytics

This is how you prove you think about the business impact of your code, not just the code itself.

After you've used a feature flag to ship an experiment, you have to measure it. This is where data collection comes in. In an interview, this topic connects the technical details of the frontend to the business goals. Your ability to design a system that produces clean, reliable data for experiment analysis is a strong signal of seniority.

Define your instrumentation strategy

Before you write a line of tracking code, you must know what you're measuring. An analytics strategy for an experiment has two core event types.

Exposure events: These fire when a user is exposed to a variant of an experiment. This event tells your analytics system, "User 123 saw the 'control' version of the new-checkout-button experiment." Without this, you can't segment users into experiment groups.

Metric events: These track the user behaviors you believe the experiment will affect. For a new checkout button, the primary metric event might be order_completed. You might also track secondary metrics like payment_info_submitted or shipping_address_error.

The trap: Don't just start tracking everything. This creates noise, costs money, and can slow down the client. Conversely, failing to track the one key metric makes the entire experiment useless. A senior answer always starts with collaborating with product and data science to define a clear hypothesis and a minimal, sufficient set of events.

A good strategy is codified in a data taxonomy or schema. This is a document that defines event names, their triggers, and the properties they include. For example:

  • experiment_viewed
    • experiment_name: (string) e.g., "new-checkout-button"
    • variant: (string) e.g., "control", "variant_A"
  • order_completed
    • order_id: (string)
    • order_total: (number)
    • currency: (string)

This schema becomes the contract between the frontend, backend, and the data analysis platform.

Choose your transport: client-direct vs. server-proxy

Once you know what to send, you have to decide how to send it. There are two main architectures.

Client-direct collection is the simplest approach. The frontend app integrates an analytics SDK (from Google Analytics, Amplitude, etc.) and calls it directly. The SDK handles batching, retries, and sending data to the analytics provider's API. This is fast to implement and works for many use cases. The main drawbacks are performance impact from the SDK and data loss from ad blockers, which block requests to known analytics domains.

Server-proxy collection (also called a "beacon" or "gateway") adds a middleman: your own backend. The frontend sends a lightweight request to an endpoint on your domain (e.g., /api/log). This backend service then validates, enriches, and forwards the data to one or more third-party analytics platforms.

This solves the ad blocker problem, as the initial request goes to your own domain. It also gives you more control. You can enrich events with server-side data (like geo-IP lookups), validate schemas to prevent bad data from ever reaching your analytics tool, and fan out events to multiple destinations (e.g., a data warehouse and a marketing tool) without adding more SDKs to the client. The trade-off is increased complexity and infrastructure cost.

In an interview, show you understand this trade-off. A good way to frame it is by stage of company. "For an early-stage product, I'd use a client-direct SDK to move quickly. For a mature e-commerce platform where every conversion matters and data quality is paramount, I would invest in a server-proxy to guarantee delivery and bypass ad blockers."

Implement a resilient tracking client

Regardless of the transport, the client-side implementation should be clean and robust. The best pattern is to create your own wrapper or facade around the tracking mechanism. This insulates your application from the specific analytics provider and provides a single place to add global context.

Your wrapper should automatically attach contextual data to every event, especially active experiments. This is how you connect a user's actions to the experiment variants they were exposed to.

Here is a minimal, effective analytics wrapper. It abstracts the final sending logic and automatically enriches events with context from a feature flagging system.

import { featureFlags } from './feature-flags';

// The context that gets added to every event.
function getGlobalContext() {
  return {
    page_url: window.location.href,
    timestamp: new Date().toISOString(),
    // Get active experiments from your feature flag system
    active_experiments: featureFlags.getActiveExperiments(),
  };
}

/**
 * Tracks an analytics event.
 * In a real app, this would send data to an SDK or a server-proxy endpoint.
 */
export function trackEvent(
  eventName: string,
  properties: Record<string, any>
): void {
  const eventPayload = {
    event: eventName,
    properties: {
      ...properties,
      ...getGlobalContext(),
    },
  };

  console.log('[ANALYTICS]', JSON.stringify(eventPayload, null, 2));

  // Example: sending to a server-proxy
  // navigator.sendBeacon('/api/log', JSON.stringify(eventPayload));
}

This approach makes your component code simple: trackEvent('add_to_cart_clicked', { productId: 'abc' }). All the contextual boilerplate is handled for you.

For events that fire on page unload, like checkout_abandoned, use navigator.sendBeacon(). It's a non-blocking API designed to send small payloads before a page unloads, making it more reliable than a standard fetch.

What a good answer sounds like

When asked to design a system for collecting experiment data, structure your answer to show you think through the problem from end to end.

"First, I'd clarify the goals with the product manager. What is the primary success metric for this experiment? Let's say we're testing a new sign-up button, and the goal is to increase registrations.

We'll need two key events. An experiment_viewed event with properties for experiment_name: 'new-signup-button' and the variant. And a signup_completed event.

For the architecture, given that sign-ups are critical, I'd advocate for a server-proxy. This avoids data loss from ad blockers. The client will send events to our /api/analytics endpoint.

On the frontend, I'd create a lightweight AnalyticsService wrapper. This service would have a single track method. It would automatically pull the active experiment variant from our feature flagging service and attach it to every outgoing event payload. This ensures we can always attribute user actions back to the experiment group they were in.

Finally, for any events that might fire as the user is leaving the page, I'd use navigator.sendBeacon in our service to ensure reliable delivery."

This answer covers strategy, architecture, implementation, and reliability. It demonstrates a mature understanding of the entire system.

Try it

Write a 20-line analytics wrapper function in TypeScript. It should take an eventName string and a properties object. Inside the function, add timestamp and page_url properties to the payload, then log the final object to the console. This simulates the core logic of an analytics facade.

Next: This was the final lesson. It's time to put it all together in a mock interview.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Feature Flags and Remote Configuration