0
0
Microservicessystem_design~10 mins

Database decomposition strategy 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 with its own database.

Microservices
class [1]Service:
    def __init__(self):
        self.database = DatabaseConnection('user_db')
Drag options to blanks, or click blank then click option'
AUser
BOrder
CInventory
DPayment
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a service that does not manage user data.
2fill in blank
medium

Complete the code to route a request to the correct microservice based on the database decomposition.

Microservices
def route_request(request):
    if request.type == 'order':
        return [1]Service.handle(request)
Drag options to blanks, or click blank then click option'
AUser
BPayment
COrder
DInventory
Attempts:
3 left
💡 Hint
Common Mistakes
Routing order requests to UserService or unrelated services.
3fill in blank
hard

Fix the error in the database access code for the Inventory microservice.

Microservices
class InventoryService:
    def get_stock(self, item_id):
        return self.db.[1]('SELECT stock FROM inventory WHERE id = %s', item_id)
Drag options to blanks, or click blank then click option'
Acommit
Bexecute
Cfetchall
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using fetchall before execute, or commit/connect incorrectly.
4fill in blank
hard

Fill both blanks to correctly implement database decomposition with separate connections and queries.

Microservices
class [1]Service:
    def __init__(self):
        self.db = DatabaseConnection('[2]_db')
Drag options to blanks, or click blank then click option'
APayment
Buser
Corder
DInventory
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing service names and database names incorrectly.
5fill in blank
hard

Fill all three blanks to implement a query filtering orders by status in the Order microservice.

Microservices
def get_orders_by_status(self, status):
    query = "SELECT * FROM orders WHERE status [1] %s"
    self.db.[2](query, (status,))
    return self.db.[3]()
Drag options to blanks, or click blank then click option'
A=
Bexecute
Cfetchall
Dcommit
Attempts:
3 left
💡 Hint
Common Mistakes
Using commit instead of execute or fetchall, or wrong SQL operator.