0
0
Microservicessystem_design~10 mins

Service decomposition strategies 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 microservice based on business capability.

Microservices
class [1]Service:
    def __init__(self):
        pass

    def execute(self):
        print("Executing business logic")
Drag options to blanks, or click blank then click option'
ADatabase
BCache
COrder
DLogger
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the service after technical components like 'Database' instead of business capabilities.
2fill in blank
medium

Complete the code to implement a microservice that communicates asynchronously using {{BLANK_1}}.

Microservices
def send_event(event):
    [1].publish(event)

send_event({'type': 'OrderCreated'})
Drag options to blanks, or click blank then click option'
AHTTP
BMessageQueue
CFTP
DSMTP
Attempts:
3 left
💡 Hint
Common Mistakes
Using HTTP which is synchronous instead of a message queue for async communication.
3fill in blank
hard

Fix the error in the code to correctly implement database per service pattern with {{BLANK_1}} isolation.

Microservices
class PaymentService:
    def __init__(self):
        self.db = [1]('payment_db')

    def save_payment(self, payment):
        self.db.insert(payment)
Drag options to blanks, or click blank then click option'
AFileStorage
BInMemoryCache
CSharedDatabase
DDedicatedDatabase
Attempts:
3 left
💡 Hint
Common Mistakes
Using a shared database which breaks service isolation.
4fill in blank
hard

Fill both blanks to implement API Gateway pattern with {{BLANK_1}} routing and {{BLANK_2}} aggregation.

Microservices
class APIGateway:
    def route_request(self, path):
        if path == '/orders':
            return self.[1]('OrderService')

    def aggregate_responses(self, responses):
        return [2](responses)
Drag options to blanks, or click blank then click option'
Aforward_request
Bcombine
Csend_email
Dlog_error
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated methods like sending email or logging errors for routing or aggregation.
5fill in blank
hard

Fill all three blanks to implement event-driven communication with {{BLANK_1}} publishing, {{BLANK_2}} subscribing, and {{BLANK_3}} processing.

Microservices
class InventoryService:
    def publish_event(self, event):
        [1].send(event)

    def subscribe_events(self):
        [2].listen(self.process_event)

    def process_event(self, event):
        [3].process(event)
Drag options to blanks, or click blank then click option'
AEventBus
BEventListener
CCallback
DLogger
Attempts:
3 left
💡 Hint
Common Mistakes
Using Logger instead of event components for communication.