Checks: observability and recovery
Templates for the four observability and recovery stories. These run against a test environment with load, a real orchestrator or a real alerting pipeline, so they belong in a scheduled resilience suite rather than in every commit.
C-21: scaling out doesn’t reduce completions
Section titled “C-21: scaling out doesn’t reduce completions”- Proves: under the same overload, adding workers never lowers completed jobs per second, and downstream attempts stay bounded.
- Fails for: scaling on queue depth with unbounded downstream concurrency. The autoscaler that made the backlog worse.
- Harness needs: a load generator; a downstream stub that slows down beyond a concurrency limit; metrics for completions and downstream attempts.
@Testvoid moreWorkersNeverMeanFewerCompletions() { downstreamStub.saturatesAbove(100, 200); // 100 in flight, 200 calls/s var load = loadGenerator.constant(250, Duration.ofMinutes(10));
var tenWorkers = runWith(10, load); var fortyWorkers = runWith(40, load);
assertThat(fortyWorkers.completedPerSecond()).isGreaterThanOrEqualTo(tenWorkers.completedPerSecond() * 0.95); assertThat(fortyWorkers.downstreamAttemptsPerSecond()).isLessThanOrEqualTo(200 * 1.10);}def test_more_workers_never_mean_fewer_completions(downstream_stub, load_generator, run_with): downstream_stub.saturates_above(in_flight=100, per_second=200) load = load_generator.constant(per_second=250, minutes=10)
ten, forty = run_with(workers=10, load=load), run_with(workers=40, load=load)
assert forty.completed_per_second >= ten.completed_per_second * 0.95 assert forty.downstream_attempts_per_second <= 200 * 1.10C-22: the journey alerts, not just the endpoint
Section titled “C-22: the journey alerts, not just the endpoint”- Proves: with the fulfillment worker stopped, the report counts accepted orders past their deadline and an alert fires within minutes, while the API’s availability stays at 100%.
- Fails for: endpoint-only objectives. The healthy dashboard for a broken customer journey.
- Harness needs: stop a worker; a controllable clock or a short deadline in test; read the alert pipeline.
@Testvoid aStoppedWorkerRaisesAJourneyAlertWhileTheApiStaysGreen() { fulfillmentWorker.stop(); var start = clock.now(); for (int i = 0; i < 30; i++) { checkout.placeOrder(sampleOrder(i)); clock.advance(Duration.ofSeconds(20)); }
var report = slo.report("orders-reach-warehouse-within-5m", start, clock.now()); var firstAlert = alerts.firstSince(start, "orders-reach-warehouse");
assertThat(report.breached()).isGreaterThan(0); assertThat(firstAlert).isPresent(); assertThat(Duration.between(start, firstAlert.get().firedAt())).isLessThanOrEqualTo(Duration.ofMinutes(7)); assertThat(slo.report("checkout-availability", start, clock.now()).ratio()).isEqualTo(1.0);}def test_a_stopped_worker_raises_a_journey_alert_while_the_api_stays_green( fulfillment_worker, checkout, clock, slo, alerts): fulfillment_worker.stop() start = clock.now() for i in range(30): checkout.place_order(sample_order(i)) clock.advance(seconds=20)
report = slo.report("orders-reach-warehouse-within-5m", start, clock.now()) first_alert = alerts.first_since(start, "orders-reach-warehouse")
assert report.breached > 0 assert first_alert is not None and first_alert.fired_at - start <= timedelta(minutes=7) assert slo.report("checkout-availability", start, clock.now()).ratio == 1.0The last assertion is deliberate. It documents why the endpoint objective can’t be the only one.
C-23: slow starts survive; stuck processes don’t
Section titled “C-23: slow starts survive; stuck processes don’t”- Proves: an instance that takes 90 seconds to build its index becomes ready without being restarted, and an instance that stops making progress is restarted.
- Fails for: one liveness probe that means ready. The self-healing restart that prevented recovery.
- Harness needs: a test cluster; a test image that can simulate a slow start and a hang.
@Testvoid aSlowButProgressingInstanceBecomesReadyWithoutRestarts() { var pod = cluster.deploy(searchService().withEnv("SIMULATE_INDEX_BUILD_SECONDS", "90"));
cluster.awaitReady(pod, Duration.ofMinutes(4));
assertThat(cluster.restartCount(pod)).isZero(); assertThat(cluster.firstTrafficAt(pod)).isAfter(cluster.readyAt(pod).minusSeconds(1));}
@Testvoid aStuckInstanceIsStillRestarted() { var pod = cluster.deploy(searchService().withEnv("SIMULATE_HANG_AFTER_SECONDS", "30"));
await().atMost(Duration.ofMinutes(4)).until(() -> cluster.restartCount(pod) >= 1);}def test_a_slow_but_progressing_instance_becomes_ready_without_restarts(cluster): pod = cluster.deploy(search_service(env={"SIMULATE_INDEX_BUILD_SECONDS": "90"}))
cluster.await_ready(pod, timeout=timedelta(minutes=4))
assert cluster.restart_count(pod) == 0
def test_a_stuck_instance_is_still_restarted(cluster): pod = cluster.deploy(search_service(env={"SIMULATE_HANG_AFTER_SECONDS": "30"}))
assert cluster.wait_for(lambda: cluster.restart_count(pod) >= 1, timeout=timedelta(minutes=4))Add a third check that tracks the margin: fail the build when measured start-up time exceeds 60% of the startup probe’s allowance, so the next year’s growth shows up as a failing test instead of an outage.
C-24: a cohort can fail a canary
Section titled “C-24: a cohort can fail a canary”- Proves: a canary that fails every request from one small cohort fails the gate and names the cohort, and a cohort with too little traffic is reported as insufficient observations, not as a pass.
- Fails for: a global success-rate gate. The green canary that failed a small tenant.
- Harness needs: feed the gate a recorded canary window, grouped by cohort.
@Testvoid oneFailingCohortFailsTheCanaryEvenWhenTheAggregatePasses() { var window = CanaryWindow.builder() .cohort("all-others", canary(19_989, 10), baseline(379_791, 190)) .cohort("legacy-numbering", canary(8, 8), baseline(152, 0)) .cohort("tenant-T-201", canary(3, 0), baseline(57, 0)) .build();
var verdict = canaryGate.evaluate(window);
assertThat(window.aggregateSuccessRate()).isGreaterThan(0.999); // the trap assertThat(verdict.passed()).isFalse(); assertThat(verdict.failedCohorts()).extracting(CohortResult::name).containsExactly("legacy-numbering"); assertThat(verdict.cohort("legacy-numbering")) .extracting(CohortResult::failures, CohortResult::requests).containsExactly(8L, 8L); assertThat(verdict.cohort("tenant-T-201").outcome()).isEqualTo(INSUFFICIENT_OBSERVATIONS);}def test_one_failing_cohort_fails_the_canary_even_when_the_aggregate_passes(canary_gate): window = canary_window({ "all-others": {"canary": (19_989, 10), "baseline": (379_791, 190)}, "legacy-numbering": {"canary": (8, 8), "baseline": (152, 0)}, "tenant-T-201": {"canary": (3, 0), "baseline": (57, 0)}, })
verdict = canary_gate.evaluate(window)
assert window.aggregate_success_rate > 0.999 # the trap assert not verdict.passed assert [c.name for c in verdict.failed_cohorts] == ["legacy-numbering"] assert (verdict.cohort("legacy-numbering").failures, verdict.cohort("legacy-numbering").requests) == (8, 8) assert verdict.cohort("tenant-T-201").outcome == "insufficient_observations"The numbers are the story’s canary hour: 20,000 canary requests with 18 failures, a 99.91% success rate.
Related pages
Section titled “Related pages”Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.