0
0
Microservicessystem_design~10 mins

Why advanced patterns solve edge cases in Microservices - Test Your Understanding

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

Complete the code to define a microservice that handles user requests asynchronously.

Microservices
def handle_request(request):
    # Process request asynchronously using [1]
    pass
Drag options to blanks, or click blank then click option'
Asynchronous_api
Bdirect_call
Cblocking_io
Dmessage_queue
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing synchronous methods that block the service.
2fill in blank
medium

Complete the code to implement a retry mechanism for failed microservice calls.

Microservices
def call_service():
    for attempt in range(3):
        response = send_request()
        if response.status == [1]:
            return response
    return None
Drag options to blanks, or click blank then click option'
A200
B301
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Retrying on success status instead of failure.
3fill in blank
hard

Fix the error in the circuit breaker pattern implementation by completing the condition.

Microservices
if failure_count > [1]:
    open_circuit()
Drag options to blanks, or click blank then click option'
Aretry_limit
Btimeout
Cthreshold
Dsuccess_count
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated variables like timeout or success_count.
4fill in blank
hard

Fill both blanks to implement a fallback method when the primary service fails.

Microservices
try:
    result = primary_service.call()
except [1]:
    result = [2]()
Drag options to blanks, or click blank then click option'
AServiceUnavailableError
Bfallback_service.call
CTimeoutError
Dretry_service.call
Attempts:
3 left
💡 Hint
Common Mistakes
Catching wrong exceptions or calling retry instead of fallback.
5fill in blank
hard

Fill all three blanks to implement a load balancer that distributes requests evenly.

Microservices
class LoadBalancer:
    def __init__(self, servers):
        self.servers = servers
        self.index = 0

    def get_server(self):
        server = self.servers[[1]]
        self.index = (self.index + [2]) % [3]
        return server
Drag options to blanks, or click blank then click option'
Aself.index
B1
Clen(self.servers)
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using fixed indexes or wrong modulo values.