Bird
Raised Fist0
Microservicessystem_design~10 mins

Liveness and readiness probes in Microservices - Interactive Code Practice

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a liveness probe path in a Kubernetes pod spec.

Microservices
livenessProbe:
  httpGet:
    path: [1]
    port: 8080
Drag options to blanks, or click blank then click option'
A/healthz
B/ready
C/metrics
D/status
Attempts:
3 left
💡 Hint
Common Mistakes
Using readiness probe path for liveness probe
Using metrics endpoint for liveness
2fill in blank
medium

Complete the code to define a readiness probe path in a Kubernetes pod spec.

Microservices
readinessProbe:
  httpGet:
    path: [1]
    port: 8080
Drag options to blanks, or click blank then click option'
A/healthz
B/status
C/ready
D/metrics
Attempts:
3 left
💡 Hint
Common Mistakes
Using liveness probe path for readiness probe
Using metrics endpoint for readiness
3fill in blank
hard

Fix the error in the probe configuration to correctly specify the initial delay seconds.

Microservices
livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: [1]
Drag options to blanks, or click blank then click option'
A0
B-5
C"five"
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number
Using negative or zero values
4fill in blank
hard

Fill both blanks to configure a readiness probe with a TCP socket check and a timeout.

Microservices
readinessProbe:
  tcpSocket:
    port: [1]
  timeoutSeconds: [2]
Drag options to blanks, or click blank then click option'
A8080
B5
C10
D80
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect port numbers
Setting timeout too high or zero
5fill in blank
hard

Fill all three blanks to configure a liveness probe with an exec command, initial delay, and period seconds.

Microservices
livenessProbe:
  exec:
    command:
      - [1]
      - [2]
  initialDelaySeconds: [3]
Drag options to blanks, or click blank then click option'
Acat
B/tmp/healthy
C10
Dls
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong command or file path
Setting initial delay too low

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