0
0
Microservicessystem_design~10 mins

Backend for Frontend (BFF) pattern 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 a BFF service that handles client requests.

Microservices
def bff_service(request):
    response = [1](request)
    return response
Drag options to blanks, or click blank then click option'
Astart_microservice
Bsend_to_database
Chandle_client_request
Dlog_error
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a function that sends data to the database instead of handling the client request.
2fill in blank
medium

Complete the code to forward a request from BFF to the appropriate microservice.

Microservices
def forward_request_to_service(request):
    service_response = [1](request)
    return service_response
Drag options to blanks, or click blank then click option'
Aprocess_locally
Blog_request
Cignore_request
Dcall_microservice_api
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing to process requests locally when the BFF should delegate to microservices.
3fill in blank
hard

Fix the error in the BFF code that aggregates responses from multiple microservices.

Microservices
def aggregate_responses(responses):
    combined = {}
    for response in responses:
        combined.update([1])
    return combined
Drag options to blanks, or click blank then click option'
Aresponse.items()
Bresponses
Cresponse
Dresponse.keys()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the whole dictionary without .items(), causing a TypeError.
4fill in blank
hard

Fill both blanks to create a BFF function that filters and transforms data from a microservice.

Microservices
def process_data(data):
    filtered = [item for item in data if item [1] 10]
    transformed = [item[2]2 for item in filtered]
    return transformed
Drag options to blanks, or click blank then click option'
A>
B*
C<
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication for transformation.
5fill in blank
hard

Fill all three blanks to define a BFF caching mechanism that stores and retrieves data.

Microservices
cache = {}
def get_data(key):
    if key in cache:
        return cache[[1]]
    data = fetch_from_service(key)
    cache[[2]] = data
    return cache[[3]]
Drag options to blanks, or click blank then click option'
Akey
Bdata
Ckey_value
Dcache_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for cache keys causing KeyError.