Bird
Raised Fist0
Microservicessystem_design~20 mins

Liveness and readiness probes in Microservices - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Probe Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Difference between liveness and readiness probes

Which statement correctly describes the difference between liveness and readiness probes in microservices?

ALiveness probes are used only during deployment; readiness probes are used only during runtime.
BLiveness probes check if the service is ready to accept traffic; readiness probes check if the service is alive and should be restarted if failed.
CBoth probes check if the service is alive but readiness probes run more frequently.
DLiveness probes check if the service is alive and should be restarted if failed; readiness probes check if the service is ready to accept traffic.
Attempts:
2 left
💡 Hint

Think about what happens when a service is unhealthy versus when it is not ready to serve requests.

Architecture
intermediate
2:00remaining
Choosing probe types for a microservice

You have a microservice that loads a large configuration file on startup and then serves requests. Which probe setup is best to ensure smooth traffic routing and automatic recovery?

AUse a readiness probe that checks if the configuration is loaded, and a liveness probe that checks if the service process is running.
BUse only a liveness probe that checks if the configuration is loaded.
CUse only a readiness probe that checks if the service process is running.
DUse a liveness probe that checks if the service is ready to accept traffic, and no readiness probe.
Attempts:
2 left
💡 Hint

Consider what happens if the service is running but not ready to serve requests.

scaling
advanced
2:00remaining
Impact of probe misconfiguration on scaling

What is the likely impact if a readiness probe is misconfigured to always fail in a Kubernetes deployment with autoscaling?

APods will be restarted repeatedly, causing instability in the cluster.
BPods will never receive traffic, causing autoscaler to create more pods unnecessarily.
CPods will receive traffic even if unhealthy, causing errors for users.
DAutoscaler will scale down pods aggressively, reducing availability.
Attempts:
2 left
💡 Hint

Think about how readiness affects traffic routing and autoscaling decisions.

tradeoff
advanced
2:00remaining
Tradeoffs in probe frequency settings

What is a tradeoff when setting very frequent liveness and readiness probe intervals in a microservice?

AHigher probe frequency improves failure detection speed but increases CPU and network overhead.
BHigher probe frequency reduces CPU usage but delays failure detection.
CLower probe frequency causes more false positives but reduces network traffic.
DLower probe frequency improves failure detection speed but increases memory usage.
Attempts:
2 left
💡 Hint

Consider what happens when probes run too often versus too rarely.

estimation
expert
2:30remaining
Estimating probe impact on cluster resource usage

A Kubernetes cluster runs 100 microservice pods. Each liveness probe sends a 1KB HTTP request every 10 seconds, and each readiness probe sends a 1KB HTTP request every 5 seconds. Estimate the total network bandwidth used by probes per minute.

A3600 KB per minute
B2400 KB per minute
C1800 KB per minute
D3000 KB per minute
Attempts:
2 left
💡 Hint

Calculate requests per pod per minute, multiply by request size and number of pods.

Practice

(1/5)
1. What is the main purpose of a liveness probe in microservices?
easy
A. To check if the service is ready to accept traffic
B. To log user requests for debugging
C. To monitor the network latency between services
D. To check if the service is alive and restart it if it is not

Solution

  1. Step 1: Understand the role of liveness probes

    Liveness probes detect if a service is stuck or dead and need restarting.
  2. Step 2: Differentiate from readiness probes

    Readiness probes check if the service can handle requests, not if it is alive.
  3. Final Answer:

    To check if the service is alive and restart it if it is not -> Option D
  4. Quick Check:

    Liveness probe = check alive and restart [OK]
Hint: Liveness = alive and restart, Readiness = ready for traffic [OK]
Common Mistakes:
  • Confusing liveness with readiness probes
  • Thinking liveness probes check traffic readiness
  • Assuming liveness probes monitor performance
2. Which of the following is the correct syntax to define a readiness probe in a Kubernetes pod spec?
easy
A. livenessProbe: exec: command: ["cat", "/tmp/healthy"] timeoutSeconds: 1
B. livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 5 periodSeconds: 10
C. readinessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 5 periodSeconds: 10
D. livenessProbe: httpGet: path: /ready port: 8080 failureThreshold: 3

Solution

  1. Step 1: Identify readiness probe syntax

    Readiness probes often use httpGet with path and port, plus delay and period settings.
  2. Step 2: Confirm correct fields and indentation

    readinessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 5 periodSeconds: 10 correctly shows readinessProbe with httpGet, initialDelaySeconds, and periodSeconds.
  3. Final Answer:

    readinessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 5 periodSeconds: 10 -> Option C
  4. Quick Check:

    Readiness probe syntax = readinessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 5 periodSeconds: 10 [OK]
Hint: Readiness uses httpGet with path and port in YAML [OK]
Common Mistakes:
  • Mixing livenessProbe and readinessProbe fields
  • Incorrect indentation in YAML
  • Using wrong probe type for readiness
3. Given this Kubernetes pod spec snippet, what will happen if the readiness probe fails continuously?
readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10
  failureThreshold: 3
medium
A. The pod will be restarted immediately
B. The pod will be marked as not ready and removed from service endpoints
C. The pod will ignore the failure and continue serving traffic
D. The pod will scale up automatically

Solution

  1. Step 1: Understand readiness probe failure effect

    Readiness probe failure marks pod as not ready, so it stops receiving traffic.
  2. Step 2: Differentiate from liveness probe effect

    Liveness probe failure triggers pod restart, readiness does not.
  3. Final Answer:

    The pod will be marked as not ready and removed from service endpoints -> Option B
  4. Quick Check:

    Readiness failure = pod not ready, no restart [OK]
Hint: Readiness failure removes pod from load balancer, no restart [OK]
Common Mistakes:
  • Confusing readiness failure with pod restart
  • Assuming pod scales automatically on probe failure
  • Ignoring failureThreshold effect
4. A microservice has a liveness probe configured as an HTTP GET on /health. The service sometimes returns HTTP 500 during startup but is healthy afterward. What is the best fix to avoid unnecessary restarts?
medium
A. Increase initialDelaySeconds to allow startup time before probing
B. Change the probe to readiness probe instead of liveness probe
C. Remove the probe completely to avoid restarts
D. Set failureThreshold to 1 to detect failures faster

Solution

  1. Step 1: Identify cause of restarts

    Liveness probe fails during startup because service returns HTTP 500 before ready.
  2. Step 2: Adjust probe timing to avoid false failures

    Increasing initialDelaySeconds delays probe start, allowing service to become healthy first.
  3. Final Answer:

    Increase initialDelaySeconds to allow startup time before probing -> Option A
  4. Quick Check:

    Delay liveness probe start to avoid false failures [OK]
Hint: Delay liveness probe start to avoid false failure during startup [OK]
Common Mistakes:
  • Removing probes which reduces reliability
  • Confusing readiness and liveness probe roles
  • Setting failureThreshold too low causing quick restarts
5. You have a microservice that takes time to initialize resources before it can serve requests. You want to ensure it is not restarted unnecessarily but also not receive traffic before ready. How should you configure liveness and readiness probes?
hard
A. Set liveness probe with a longer initialDelaySeconds and readiness probe to check resource initialization
B. Use only a liveness probe with a short periodSeconds to restart fast
C. Use only a readiness probe and no liveness probe
D. Set both probes to the same HTTP path and timing

Solution

  1. Step 1: Prevent unnecessary restarts during initialization

    Set liveness probe initialDelaySeconds long enough to avoid restarting while initializing.
  2. Step 2: Use readiness probe to block traffic until ready

    Readiness probe should check if resources are initialized before accepting traffic.
  3. Final Answer:

    Set liveness probe with a longer initialDelaySeconds and readiness probe to check resource initialization -> Option A
  4. Quick Check:

    Liveness delay + readiness check = safe startup [OK]
Hint: Delay liveness, readiness blocks traffic until ready [OK]
Common Mistakes:
  • Using only one probe type causing traffic or restart issues
  • Setting same path and timing for both probes
  • Not delaying liveness probe causing premature restarts