0
0
Microservicessystem_design~10 mins

Single responsibility per service 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 that handles only user authentication.

Microservices
class AuthService:
    def __init__(self):
        self.users = {}

    def [1](self, username, password):
        # Authenticate user
        return self.users.get(username) == password
Drag options to blanks, or click blank then click option'
Alog_activity
Bregister
Cauthenticate
Dsend_email
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name like 'register' which belongs to user registration service.
Including unrelated methods like 'send_email' or 'log_activity' in this service.
2fill in blank
medium

Complete the code to separate order processing into its own microservice method.

Microservices
class OrderService:
    def [1](self, order_id):
        # Process the order
        print(f"Processing order {order_id}")
Drag options to blanks, or click blank then click option'
Asend_invoice
Bprocess_order
Cupdate_inventory
Dcancel_order
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that belong to other services like 'cancel_order' or 'send_invoice'.
Mixing inventory updates inside order processing service.
3fill in blank
hard

Fix the error in the microservice code to ensure it only handles payment processing.

Microservices
class PaymentService:
    def process_payment(self, amount):
        print(f"Processing payment of ${amount}")

    def {{BLANK_2}}(self, order_id):
        print(f"Sending receipt for order {order_id}")
Drag options to blanks, or click blank then click option'
Aamount
Bupdate_order_status
Csend_receipt
Drefund_payment
Attempts:
3 left
💡 Hint
Common Mistakes
Including order status updates in payment service.
Using incorrect variable names causing runtime errors.
4fill in blank
hard

Fill both blanks to correctly separate user profile and notification services.

Microservices
class UserProfileService:
    def update_profile(self, user_id, data):
        print(f"Updating profile for user {user_id}")

class NotificationService:
    def [1](self, user_id, message):
        print(f"Sending [2] to user {user_id}")
Drag options to blanks, or click blank then click option'
Asend_notification
Bsend_email
Cnotification
Dupdate_profile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update_profile' method in notification service.
Printing 'send_email' when the method is generic notification.
5fill in blank
hard

Fill all three blanks to design a microservice that only manages product inventory.

Microservices
class InventoryService:
    def [1](self, product_id, quantity):
        print(f"Adding {quantity} units to product {product_id}")

    def [2](self, product_id):
        print(f"Checking stock for product {product_id}")

    def [3](self, product_id, quantity):
        print(f"Removing {quantity} units from product {product_id}")
Drag options to blanks, or click blank then click option'
Aadd_stock
Bcheck_stock
Cremove_stock
Dupdate_price
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'update_price' method in inventory service.
Using unclear method names that do not reflect inventory management.