0
0
Microservicessystem_design~10 mins

Service discovery concept 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 register a service instance with the discovery server.

Microservices
discovery_client.register_service('[1]', '10.0.0.1', 8080)
Drag options to blanks, or click blank then click option'
Aservice_id
Bservice_name
Cservice_port
Dservice_address
Attempts:
3 left
💡 Hint
Common Mistakes
Using IP address or port as the service identifier.
Confusing service ID with service name.
2fill in blank
medium

Complete the code to discover the address of a service instance.

Microservices
address = discovery_client.get_service_address('[1]')
Drag options to blanks, or click blank then click option'
Ainstance_id
Bservice_port
Cservice_name
Dnode_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using instance ID instead of service name.
Using port number or node ID which are not keys for discovery.
3fill in blank
hard

Fix the error in the service registration code to include health check.

Microservices
discovery_client.register_service('payment-service', '10.0.0.5', 9090, health_check='[1]')
Drag options to blanks, or click blank then click option'
Ahttp://10.0.0.5:9090/health
B10.0.0.5:9090
C/health
Dhealth
Attempts:
3 left
💡 Hint
Common Mistakes
Providing only a path or IP without protocol.
Using a keyword instead of a URL.
4fill in blank
hard

Fill both blanks to create a dictionary of service instances filtered by status.

Microservices
healthy_services = {id: info for id, info in services.items() if info['[1]'] == '[2]'}
Drag options to blanks, or click blank then click option'
Astatus
Bhealthy
Caddress
Dactive
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'address' as a key for filtering.
Using 'active' instead of 'healthy' as status value.
5fill in blank
hard

Fill all three blanks to implement a simple client-side load balancer picking a random healthy instance.

Microservices
import random

instances = discovery_client.get_service_instances('[1]')
healthy = [i for i in instances if i['[2]'] == '[3]']
selected = random.choice(healthy)
Drag options to blanks, or click blank then click option'
Aorder-service
Bstatus
Chealthy
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong service name.
Filtering by wrong key or value.
Not filtering before choosing randomly.