Architecture Decisions for an Online Experimentation System
System DesignModel answerLast updated
Architect an experimentation engine balancing sync/async validation, strict latency budgets, and experiment health monitoring.
In a system design discussion focused on infrastructure for online A/B testing, you are asked to dive into three core operational challenges:
- Validation Pipeline (Sync vs. Async): Deciding which configuration and data integrity checks must block operational workflows versus running asynchronously in the background.
- Latency Budget Preservation: Designing the evaluation/assignment pipeline so product microservices can determine feature variants without exceeding tight latency SLAs.
- Health Checking & Safety Automation: Monitoring both infrastructure health and statistical experiment validity, including automated circuit breakers for broken or harmful variants.
Assume a standard online experimentation architecture comprising:
- A Control Plane (UI/API for experiment configuration, audience targeting rules, variant traffic splits, metric definitions).
- An Assignment Engine (evaluates rules for incoming user requests to yield a variant).
- An Event Ingestion Pipeline (logs exposures and conversion events).
- An Analytics/Statistical Engine (computes metrics, sample ratio mismatches, and guardrails).
Key Areas to Address
-
Synchronous vs. Asynchronous Validation
- Define clear principles for separating blocking (synchronous) checks from non-blocking (asynchronous) background validations across two distinct stages: experiment configuration time and runtime event ingestion.
- Detail concrete checks for both stages and describe the consequences of incorrectly placing a check on the wrong side of the boundary.
-
Latency Budget & In-Process vs. Remote Assignment
- Detail how variant evaluation stays within caller latency limits (e.g., sub-millisecond budgets).
- Compare in-process SDK evaluation via local rule caching against remote RPC-based evaluation.
- Explain how configuration updates are propagated safely without impacting live request execution.
- Define fallback behavior when timeouts occur and explain how fallbacks interact with data logging to prevent experiment corruption.
-
Platform and Experiment Health Checks
- Distinguish between platform infrastructure checks (propagation delay, ingestion backpressure) and statistical health checks (Sample Ratio Mismatch, guardrail metric degradation).
- Specify automated remediation policies (auto-kill switch vs. alert-only) and explain how to prevent false positives caused by continuous statistical testing.
Hints
Hint 1
Rule evaluation latency can be eliminated from network calls by performing in-process deterministic evaluation via a local config cache.
Hint 2
Consider how defaulting on SDK timeout affects variance and bias in the analysis pipeline—should defaulted requests log an exposure?
Hint 3
Beware of sequential testing bias when implementing automated statistical health checks; continuous p-value monitoring inflates Type I errors.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
High-Level Architecture Overview
+-------------------------+
| Control Plane (UI) |
+------------+------------+
|
(Async Validation / CD)
|
v
+-------------------------+
| Config Storage / CDN |
+------------+------------+
|
(Local Polling / Server-Sent Events)
|
v
+-----------------------------------------------------------------------+
| Calling Product Microservice |
| |
| +------------------------+ +-------------------------------+ |
| | In-Process SDK |<-------| Local Rule Cache | |
| | | | (Evaluates MurmurHash3) | |
| +-----------+------------+ +-------------------------------+ |
+--------------|--------------------------------------------------------+
|
(Non-blocking Log Event)
v
+-----------------------------------------------------------------------+
| Streaming Ingestion (Kafka) |
+--------------+--------------------------------------------------------+
|
v
+-----------------------------------------------------------------------+
| Async Validation & Statistical Health Pipeline |
| - SRM Detection (Chi-Square) |
| - Guardrail Alerting / Automated Kill-Switch |
+-----------------------------------------------------------------------+
Part 1 — Synchronous vs. Asynchronous Validation
Principles of Classification
Checks are classified using three criteria:
- Cost & Latency: Operations requiring full data scans, cross-system DB reads, or complex compute must run asynchronously.
- Determinism: Pure schema validation or structural validation runs synchronously.
- Harm of Failure: If an invalid state corrupts downstream statistical models or crashes callers, validation must block synchronously.
| Stage | Validation Type | Execution Mode | Failure Consequence if Misplaced |
|---|---|---|---|
| Config Creation | Schema & Mutex Checks (e.g., overlapping targeting keys, invalid JSON rules, mutually exclusive experiment groups). | Synchronous (Blocks Save/Launch) | If moved to Async: Invalid configs hit the edge, causing SDK runtime crashes or silent misallocation of users. |
| Config Creation | Historical Power Analysis & Metric Conflict Check (checking if metric definitions exist or if target sample size is feasible). | Asynchronous (Warning in UI) | If moved to Sync: Blocks rollout workflow for minutes while performing heavy analytical queries on historical data tables. |
| Data Ingestion | Schema Validation & ID Format Checks (validating envelope format, timestamp bounds). | Synchronous (Ingestion Pipeline Gate) | If moved to Async: Poison pill payloads enter the stream, causing batch parsing failures downstream. |
| Data Ingestion | Sample Ratio Mismatch (SRM) & Metric Anomaly Detection. | Asynchronous (Stream Processing Worker) | If moved to Sync: Ingestion pipeline throughput degrades; network latency spikes for event callers. |
Handling Asynchronous Failures
When an asynchronous validation fails (e.g., an invalid metric definition or dynamic overlap detected post-launch):
- The control plane marks the experiment state as
WARNINGorDEGRADED. - An event is dispatched to an alert topic, notifying experiment owners via Slack/PagerDuty.
- If the failure threatens data integrity (e.g., dynamic rule conflict), an automated workflow transitions the experiment to a safe state (serving default control) without deleting historical audit trails.
Part 2 — Latency Budgets & Assignment Strategy
Remote RPC vs. In-Process SDK Evaluation
To respect a strict latency budget (e.g., $< 1\text{ ms}$ allocated to feature flag evaluation):
- Remote RPC Model: The calling service queries an external assignment cluster over gRPC/HTTP.
- Pros: Instant rule propagation; small caller memory footprint.
- Cons: Adds network round-trips ($2\text{--}15\text{ ms}$ p99), vulnerable to network partition, introduces a single point of failure for all service traffic.
- In-Process SDK Model (Recommended): The SDK pulls rule configurations periodically (or receives updates via SSE/WebSockets) and evaluates assignments locally in-memory.
- Pros: Evaluation latency drops to sub-microsecond levels ($< 10\text{ }\mu\text{s}$ using deterministic hashing like MurmurHash3); zero network dependency during request execution.
- Cons: Config propagation delay (typically 1 to 5 seconds); memory overhead inside the host process.
Local Evaluation Mechanics & Determinism
The SDK computes assignments deterministically: $$\text{Bucket} = \text{MurmurHash3}(\text{userID} + \text{experimentID}) \pmod{100}$$ This guarantees that given the same user ID and configuration, any instance evaluates the exact same variant locally without inter-process communication.
Fallback Behavior & Data Integrity
When an SDK experiences cache cold-starts, missing keys, or rule evaluation timeouts:
- Fallback Action: The SDK immediately returns the
Control(default) variant defined in code. - Exposure Logging Rule: The SDK must not log an exposure event for a failed evaluation or fallback invocation.
- Reason: Logging fallbacks as exposures pollutes the treatment group distribution, biasing statistical estimates (introducing Type II errors or dilution). Fallback occurrences are reported exclusively to an internal platform operational metric (
sdk.eval.fallback_count).
- Reason: Logging fallbacks as exposures pollutes the treatment group distribution, biasing statistical estimates (introducing Type II errors or dilution). Fallback occurrences are reported exclusively to an internal platform operational metric (
Part 3 — Health Checks & Automated Guardrails
1. Platform Infrastructure Health Checks
- Config Sync Drift: SDKs periodically report their active configuration version hash via heartbeats. If $> 1%$ of instances lag behind by $> 30$ seconds, an infrastructure alert fires.
- Ingestion Lag: Measures delay between event timestamp and processing timestamp in the ingestion queue. If lag exceeds threshold, batch jobs pause calculation to avoid partial-data bias.
2. Statistical & Experiment Health Checks
Sample Ratio Mismatch (SRM)
Compares actual exposure counts against configured traffic splits (e.g., expected 50/50 vs actual 52/48).
- Algorithm: Chi-Square Goodness-of-Fit test. $$\chi^2 = \sum \frac{(O_i - E_i)^2}{E_i}$$
- Threshold: $p < 0.001$.
- Action: Automatically flag experiment, halt traffic allocation changes, and notify the owner. SRM indicates severe bias (e.g., SDK crash on a specific variant).
Guardrail Metric Violation
Monitors critical business health indicators (e.g., app crash rate, latency p99, checkout conversion rate).
+-----------------------------+
| Continuous Metric Ingestion |
+--------------+--------------+
|
v
+-----------------------------+
| Sequential Probability Test |
| (mSPRT Boundary Check) |
+--------------+--------------+
|
+-----------+-----------+
| |
[Boundary Exceeded] [Within Limits]
| |
v v
+------------------------------+ +----------+
| Trigger Automated Cutoff | | Continue |
| - Force traffic to Control | +----------+
| - Emit PagerDuty Alert |
+------------------------------+
- Automated Action: If a guardrail metric degrades past a safety boundary (e.g., crash rate increases by $> 0.5%$ relative to control at $p < 0.0001$), the system triggers an Automated Circuit Breaker:
- The experiment status switches to
KILLED. - Rule config updates propagate to push 100% of traffic to the
Controlvariant. - Exposure logging for the treatment variant is disabled.
- The experiment status switches to
Avoiding False Positives in Continuous Testing
Repeatedly running standard fixed-horizon hypothesis tests ($t$-tests or Chi-Square) every minute drastically increases the cumulative Type I error rate ($\alpha$ spending problem).
To prevent false alarms:
- Use Mixture Sequential Probability Ratio Tests (mSPRT) or Always-Valid p-Values.
- Define a strict stopping boundary adjusted for continuous monitoring: $$\text{Reject } H_0 \text{ when } \text{mSPRT Stat} > \frac{1}{\alpha_{\text{target}}}$$ This allows continuous automated safety evaluation of live streaming data without falsely triggering kill-switches on temporary random noise.