Observability and load shedding
Quick answer
Observability helps explain system behavior from emitted signals. Load shedding rejects some work before overload consumes all available resources.
Measure useful signals and protect capacity
Metrics summarize counts, durations and resource usage; structured logs capture selected events; traces connect related operations across boundaries. Avoid secret payloads and high-cardinality metric labels such as raw request IDs. Define a service-level indicator and its measurement window before setting an objective. Admission decisions should occur before expensive work; clients need bounded retry behavior. The following counts are synthetic, not measured production data.
fn accept(in_flight: usize, limit: usize) -> bool { in_flight < limit }fn main() { println!("{} {}", accept(3, 4), accept(4, 4)); }Expected stdout (not executed):
true falseA concurrent implementation needs an atomic reservation or semaphore permit, not a separate unchecked read and increment.
fn ratio(good: u32, total: u32) -> Option<f64> { if total == 0 || good > total { None } else { Some(f64::from(good) / f64::from(total)) }}fn main() { println!("{:.1}%", ratio(98, 100).unwrap() * 100.0); println!("{:?}", ratio(0, 0));}Expected stdout (not executed):
98.0%NoneNo observations is not proof of perfect availability. Define whether rejected requests count in the denominator.
Common mistake
Do not measure only accepted requests and then claim the service met an availability objective for all requests.
Try it yourself
Design bounded outcome labels and a synthetic test that rejects excess requests while counting them in the chosen indicator.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Observability and load shedding — practice quiz
Choose one answer per question. Code examples are predictions; review explanations after attempting them.
A service rejects overloaded requests before expensive work. How should availability measurement treat them?
Observability and load shedding — example 1. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn accept(in_flight: usize, limit: usize) -> bool { in_flight < limit } fn main() { println!("{} {}", accept(3, 4), accept(4, 4)); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.
Observability and load shedding — example 2. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn ratio(good: u32, total: u32) -> Option<f64> { if total == 0 || good > total { None } else { Some(f64::from(good) / f64::from(total)) } } fn main() { println!("{:.1}%", ratio(98, 100).unwrap() * 100.0); println!("{:?}", ratio(0, 0)); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.