Quick revision
The short answer
With four weeks to go, the safe plan is to scale up and reduce work: profile the engine, load test a larger machine at twice today's traffic with attention to GC, cut wasted recalculations, and add a warm standby so a crash on the bigger box does not mean a long outage. Partitioning the engine is the right long-term answer, but it needs routing, cross-partition handling and rebalancing, so we design it after the season with measured data.
What to remember
In this answer, we saw that the safe four-week plan is to measure first, reduce the work per event, scale up to a load-tested larger machine with GC checked, and add a warm standby with snapshots so the bigger single machine does not mean a long outage. Partitioning by product or category is the right next step, but it needs routing, cross-partition handling and rebalancing, so we design it after the season with real data.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
With four weeks to go, the safe plan is to scale up and reduce work: profile the engine, load test a larger machine at twice today's traffic with attention to GC, cut wasted recalculations, and add a warm standby so a crash on the bigger box does not mean a long outage. Partitioning the engine is the right long-term answer, but it needs routing, cross-partition handling and rebalancing, so we design it after the season with measured data.
Why this question is asked
This question tests judgement more than technology. Partitioning sounds like the grown-up answer, but a rushed re-architecture four weeks before the busiest period of the year is how teams turn a capacity problem into an outage. Interviewers want to see us separate what is safe now from what is right later. In this answer, we will recap vertical and horizontal scaling, do the capacity arithmetic, compare the options, lay out a week-by-week plan, cover failure handling for a bigger single machine, and sketch the partitioned design we would build afterwards.
1A Quick Recap: Scaling Up Versus Scaling Out
Scaling up, or vertical scaling, means moving to a bigger machine: more cores, more memory, faster disks. The code does not change, which is why it is low risk. Its limits are the largest machine we can buy and the fact that one machine is still one failure.
Scaling out, or horizontal scaling, means running many machines that each do part of the work. For a stateful engine like this one, that means partitioning: splitting the 30 GB of state by a key, such as product or category, so each node owns a slice. It removes the ceiling, but every piece of logic that assumed all state lives in one process has to be revisited.
There is a third lever that people forget under pressure: doing less work. If half the recalculations change nothing, removing them is worth as much as doubling the hardware.
2Doing the Capacity Arithmetic
Today the engine runs at 70 percent CPU. If traffic doubles and cost per event stays the same, we would need about 140 percent of today's machine, which simply does not fit. A machine with twice the cores would land near 70 percent again, which is too close to the edge for a sales peak; we want headroom, so we should aim for something like 2.5 to 3 times today's compute, or cut the work per event.
But CPU does not always scale linearly with cores. If the engine has a hot lock, a single-threaded event loop or heavy garbage collection, more cores may buy very little. That is why the first step is profiling, not shopping. A profiler such as async-profiler or Java Flight Recorder shows where the time goes, and GC logs show whether pauses grow with the 30 GB heap.
With a 30 GB heap, a low-pause collector such as G1 or ZGC usually behaves well, but a 50 ms pause today can stretch when allocation doubles, so we test GC at the target load.
| Option | Gain | Risk in four weeks |
|---|---|---|
| Bigger machine | about 2x to 3x compute, no code change | low, if load tested and GC checked |
| Reduce work per event | often 30 to 60 percent fewer recalculations | low to medium, small code changes |
| Read replicas of the state | moves read-only queries off the engine | medium, needs a feed of state changes |
| Partition the engine | no ceiling on growth | high: routing, cross-partition prices, rebalancing |
The table below puts the options side by side with what each costs within our four weeks.
3Reducing the Work Instead of Buying More
Recalculating every price on every event is often far more work than needed. If ten stock updates for one product arrive within 100 ms, we can debounce them: collect events per product for a short window and recalculate once. If an event touches a field that no pricing rule reads, we can skip it entirely. Both changes are small, testable and measurable in production before the peak.
Read traffic is another target. If other systems query current prices directly from the engine, those reads compete with recalculation for the same CPU. We can publish each new price to a store such as Redis, or to read-only replicas of the engine state fed by its change stream, and point readers there. The engine then spends its cycles on the one thing only it can do.
Notice that debouncing trades a little freshness, 100 ms here, for a large cut in work. We should confirm with the business that a price can lag an event by that much.
4The Four-Week Plan
Week one is measurement: profile the engine under replayed production traffic, record CPU per event, GC pauses and lock contention, and get a quote and quota for the larger instance. Week two is the cheap wins: deploy debouncing and event filtering behind a flag, move read queries off the engine, and measure the drop in CPU per event.
Week three is the bigger machine: run a load test at 2x and 2.5x the forecast on it, watching p99 latency and GC, then cut over in a quiet window with a rollback path to the old machine. Week four is freeze and rehearsal: no new features, a tested failover to the standby, dashboards and alerts on CPU, event lag and pause time, and a runbook for shedding non-critical events if the forecast is wrong.
- Week 1: profile and measureCPU per event, GC, locks, replayed traffic
- Week 2: reduce workdebounce, filter events, move reads off
- Week 3: scale upload test at 2x to 2.5x, cut over
- Week 4: freeze and rehearsefailover drill, alerts, shedding runbook
4 steps in order. Play them, or step through them one at a time.
5Protecting a Bigger Single Point of Failure
A bigger machine makes its own failure more expensive. If the engine crashes and has to rebuild 30 GB of state from the database or by replaying events, the reload could take many minutes, and during a sale that is lost revenue. So alongside the bigger machine we add a warm standby: a second instance of the same size that consumes the same event stream and keeps the same state, ready to take over.
With the events in a durable log such as Kafka, the standby simply reads the same topic. The active engine writes periodic snapshots of its state to object storage such as S3, so even a cold rebuild starts from a recent snapshot plus a few minutes of events rather than from zero. Failover then becomes a routing change that takes seconds, which we rehearse in week four.
6After the Season: Designing the Partitioned Engine
Once the peak has passed, we have real measurements of what the bigger machine handled, and we can design the partitioned version calmly. We pick a partition key that keeps most pricing rules inside one partition, often product or category, and route events by that key, for example by using it as the Kafka message key so each partition of the topic feeds one engine node.
The hard parts are the exceptions. Bundle prices or category-wide promotions may span partitions, so they need either a coordinating step or a small shared service. Rebalancing, moving a slice of state when we add a node, needs snapshots per partition. Built over a quarter, this means the next growth step no longer depends on finding a larger machine.
7Follow-up questions
How would you rebuild the 30 GB state quickly after a crash?
We avoid rebuilding from scratch. The engine writes a snapshot of its state to object storage every few minutes, along with the event log offset it reflects. After a crash, a new instance loads the latest snapshot, which for 30 GB over a fast network takes a few minutes, then replays events from the stored offset to catch up. Better still, a warm standby already holds the state in memory, so failover is a routing switch and the rebuild happens in the background on a replacement standby.
Why not partition now if it is the right long-term answer?
Because partitioning changes correctness, not just capacity. Routing, prices that span partitions and rebalancing each bring new failure modes, and four weeks is not enough to build and harden them before the period when an outage costs the most. A larger machine plus less work per event carries us through the peak at low risk, and gives us real data for the partitioned design.
8Conclusion
In this answer, we saw that the safe four-week plan is to measure first, reduce the work per event, scale up to a load-tested larger machine with GC checked, and add a warm standby with snapshots so the bigger single machine does not mean a long outage. Partitioning by product or category is the right next step, but it needs routing, cross-partition handling and rebalancing, so we design it after the season with real data.
Open with
I would separate what is safe in four weeks from what is right long term. At 70 percent CPU, doubled traffic needs roughly 140 percent of today's machine, so I need either about two and a half times the compute or less work per event.
Then, if they want more
First I would profile under replayed traffic to check that more cores will actually help and how GC behaves with a 30 GB heap. Then I would take the cheap wins: debounce recalculations per product, skip events that cannot change a price, and move read queries to a separate store.
Next I would load test a larger instance at two to two and a half times the forecast and cut over with a rollback path.
Because a bigger single machine makes a crash more costly, I would run a warm standby consuming the same event stream and take regular snapshots so recovery is a routing switch, not a 30 GB reload.
Partitioning by product or category is where I would go next, but it needs routing, handling for prices that span partitions and rebalancing, so I would design it after the season using the measurements we gathered.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How would you decide between a bigger machine, partitioning the engine, and other...": https://scrivio-interview-library.netlify.app/architecture/sd-fundamentals/45c6a772b8/