0
0
Microservicessystem_design~10 mins

Why good service boundaries prevent coupling 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 service boundary that isolates user data.

Microservices
class UserService:
    def get_user_profile(self, user_id):
        return self.[1].fetch_profile(user_id)
Drag options to blanks, or click blank then click option'
Aexternal_api
Bcache
Cdatabase
Dlogger
Attempts:
3 left
💡 Hint
Common Mistakes
Using external APIs directly inside the service causes tight coupling.
2fill in blank
medium

Complete the code to ensure communication between services uses APIs, not direct database calls.

Microservices
def get_order_details(order_id):
    return [1].call('OrderService', order_id)
Drag options to blanks, or click blank then click option'
AFileSystem
BApiGateway
CDirectDBConnection
DDatabaseClient
Attempts:
3 left
💡 Hint
Common Mistakes
Calling databases directly from other services increases coupling.
3fill in blank
hard

Fix the error in the service design to avoid tight coupling.

Microservices
class PaymentService:
    def process_payment(self, payment_info):
        # Incorrect: directly accessing OrderService database
        orders = [1].query_orders(payment_info.order_id)
        # process payment logic
        return True
Drag options to blanks, or click blank then click option'
ACacheService
BOrderDatabase
CPaymentGateway
DOrderServiceAPI
Attempts:
3 left
💡 Hint
Common Mistakes
Using OrderDatabase directly causes tight coupling.
4fill in blank
hard

Fill both blanks to define a service boundary and communication method that prevent coupling.

Microservices
class InventoryService:
    def check_stock(self, product_id):
        stock = self.[1].get_stock(product_id)
        return stock if stock > 0 else None

class OrderService:
    def place_order(self, product_id):
        available = [2].check_stock(product_id)
        if available:
            # proceed with order
            return True
        return False
Drag options to blanks, or click blank then click option'
AInventoryDatabase
BInventoryServiceAPI
CDirectDBConnection
DCacheLayer
Attempts:
3 left
💡 Hint
Common Mistakes
Using InventoryDatabase or DirectDBConnection causes tight coupling.
5fill in blank
hard

Fill all three blanks to implement a loosely coupled microservice interaction.

Microservices
class ShippingService:
    def ship_order(self, order_id):
        order_info = [1].get_order(order_id)
        if order_info and order_info.status == [2]:
            [3].initiate_shipping(order_id)
            return True
        return False
Drag options to blanks, or click blank then click option'
AOrderServiceAPI
B'PAID'
CLogisticsServiceAPI
DOrderDatabase
Attempts:
3 left
💡 Hint
Common Mistakes
Accessing OrderDatabase directly or skipping status check causes coupling.