Frontend System Design · Lesson 84 of 86 · 4 min
Client-Side vs Server-Side A/B Testing
This is a classic trade-off question. Your answer shows if you think about user experience, performance, and engineering cost.
When an interviewer asks you to design a system that involves A/B testing, they're listening for your default choice and your reasoning. Your ability to articulate the trade-offs between client-side and server-side execution is a strong signal of seniority. This lesson gives you a clear framework for that discussion.
How client-side testing works (and where it breaks)
In a client-side test, the server sends the same default page to every user. Then, a JavaScript SDK from a service like Optimizely or VWO runs in the browser, determines if the user is in an experiment, and manipulates the DOM to show the variant.
This approach is popular with marketing and growth teams because it lets them change copy, colors, or simple layouts without a full engineering deployment cycle.
The trap: The user pays the price in performance and experience. The browser renders the original page first, and then the script modifies it. This causes a "flicker" or Flash of Original Content (FOOC), where users see the old content for a moment before it changes. It looks broken and can invalidate your test results.
The only way to manage this is to hide the content until the test logic runs. This trades one problem for another: you're now intentionally delaying when the user sees content, which can hurt your Largest Contentful Paint (LCP).
This code shows the basic flicker mitigation pattern. You hide the element with CSS, apply the variant with JS, and then unhide it.
// A/B SDK function (simplified)
function getVariant(experimentName: string): 'control' | 'variant' {
// In a real system, this is deterministic based on a stable user ID.
return Math.random() < 0.5 ? 'control' : 'variant';
}
const element = document.getElementById('hero-section');
if (element) {
// 1. Hide the element immediately to prevent flicker.
// This class should be in your stylesheet to apply instantly.
element.classList.add('experiment-loading');
const variant = getVariant('hero-redesign');
if (variant === 'variant') {
const title = element.querySelector('h1');
if (title) {
title.textContent = 'A Brand New Headline';
}
}
// For the control group, we do nothing to the content.
// 2. Unhide the element after changes are applied.
element.classList.remove('experiment-loading');
}
/* In your CSS, loaded in the <head> */
.experiment-loading {
visibility: hidden;
}
Why server-side is the robust default
In a server-side test, the decision happens before the page is ever sent to the browser.
The server receives a request, identifies the user, determines their experiment variant, and renders the correct HTML from the start. The browser receives a page that is already finalized.
There is no flicker. There are no layout shifts from post-load DOM manipulation. The page works perfectly even if JavaScript fails. It's faster for the user because there's no extra client-side script to download and execute during the critical rendering path.
Server-side is the only acceptable choice for testing anything significant:
- Changes to a checkout flow or business logic.
- Different pricing models.
- New API response structures.
- Search algorithm changes.
It's also better for SEO, as crawlers always see the final, fully-rendered content.
How to frame the decision in an interview
Start your answer by establishing server-side testing as your professional default. This shows you prioritize a robust, performant user experience.
"I'd advocate for server-side testing as the default for any significant experiment. It provides a flicker-free, performant experience and is the only way to reliably test changes to business logic or critical user flows. The engineering cost is higher upfront but pays off in data quality and user trust."
Then, show your pragmatism by explaining when client-side is an acceptable trade-off.
"However, for purely cosmetic changes driven by a marketing team—like changing button copy or a hero image—client-side testing can be a practical tool. It allows for faster iteration without a full backend deployment for every tweak, provided we aggressively mitigate flicker and monitor the performance impact."
A more advanced answer introduces a hybrid approach. The server determines the variant and sends a flag down with the initial page load (e.g., in a JSON object). A client-side framework like React reads this flag and renders the correct component tree from the start. This avoids both heavy DOM manipulation and the need for the server to maintain completely separate render paths. It combines server authority with client-side rendering flexibility.
The consistency trap
An A/B test is useless if a user sees the control version on one page load and the variant on the next. This contaminates your data and creates a jarring user experience.
Assignment must be deterministic and sticky. Given the same user and the same experiment, the assignment logic must always return the same variant.
This is done by bucketing the user based on a stable identifier. For logged-in users, this is their user ID. For anonymous users, it's a unique ID stored in a long-lived cookie. You hash this ID against an experiment ID to consistently place the user into a bucket (e.g., "control" or "variant").
Using Math.random() for variant assignment is a classic junior mistake. It proves you haven't considered the data integrity required to get meaningful results.
Try it
Open a major e-commerce or media site in your browser. Use the developer tools' network tab to block requests containing "optimizely", "vwo", or "adobe". Reload the page a few times. Can you spot content that flickers or shifts? That's client-side testing in action.
Next: Learn how the underlying infrastructure for both A/B testing and safe rollouts works in Feature Flags and Remote Configuration.
Lock it in — apply this lesson under interview conditions.