0
0
Microservicessystem_design~10 mins

Canary deployment in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the percentage of traffic routed to the new version in a canary deployment.

Microservices
canary_traffic_percentage = [1]
Drag options to blanks, or click blank then click option'
A10
B100
C0
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Setting traffic to 100% immediately defeats the purpose of canary.
Using 0% means no traffic reaches the new version.
2fill in blank
medium

Complete the code to check if the canary deployment is healthy before increasing traffic.

Microservices
if canary_health_status == [1]:
    increase_traffic()
Drag options to blanks, or click blank then click option'
A"healthy"
B"degraded"
C"failed"
D"unknown"
Attempts:
3 left
💡 Hint
Common Mistakes
Increasing traffic when status is 'failed' or 'degraded' causes errors.
Using 'unknown' status is unsafe.
3fill in blank
hard

Fix the error in the traffic routing rule to send 20% traffic to the canary version.

Microservices
route_traffic(canary_version, percentage=[1])
Drag options to blanks, or click blank then click option'
A200
B"20%"
C20
D0.2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.2 may be interpreted as 0.2%.
Using '20%' as a string may cause errors.
Using 200 exceeds 100%.
4fill in blank
hard

Fill both blanks to define a canary deployment function that routes traffic and monitors health.

Microservices
def canary_deploy(version, traffic_percentage):
    route_traffic(version, percentage=[1])
    status = check_health(version)
    if status == [2]:
        return "Canary is healthy"
    else:
        return "Canary failed"
Drag options to blanks, or click blank then click option'
Atraffic_percentage
B"healthy"
C"failed"
Dversion
Attempts:
3 left
💡 Hint
Common Mistakes
Hardcoding traffic percentage instead of using the argument.
Checking for 'failed' instead of 'healthy' to confirm success.
5fill in blank
hard

Fill all three blanks to implement a canary deployment loop that gradually increases traffic.

Microservices
traffic = [1]
while traffic <= 100:
    route_traffic('canary', percentage=traffic)
    health = check_health('canary')
    if health != [2]:
        rollback('canary')
        break
    traffic += [3]
Drag options to blanks, or click blank then click option'
A10
B"healthy"
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Starting traffic at 5% but increasing by 10% causes uneven steps.
Checking for health not equal to 'healthy' incorrectly.
Increasing traffic by 5% instead of 10% may slow rollout.