0
0
Microservicessystem_design~10 mins

Database per service 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 microservice with its own database.

Microservices
class OrderService {
    constructor() {
        this.db = new [1]();
    }
}
Drag options to blanks, or click blank then click option'
AOrderDatabase
BCommonStorage
CSharedDatabase
DGlobalDB
Attempts:
3 left
💡 Hint
Common Mistakes
Using a shared or global database instead of a service-specific one.
2fill in blank
medium

Complete the code to ensure data isolation between services.

Microservices
function getUserData() {
    return [1].query('SELECT * FROM users');
}
Drag options to blanks, or click blank then click option'
ASharedDB
BGlobalUserDB
CUserServiceDB
DCommonDB
Attempts:
3 left
💡 Hint
Common Mistakes
Querying a shared or global database causing data coupling.
3fill in blank
hard

Fix the error in the service communication to avoid direct database sharing.

Microservices
class PaymentService {
    constructor() {
        this.db = new [1]();
    }

    processPayment() {
        // Should not access OrderService database directly
        this.db.query('UPDATE orders SET status = "paid" WHERE id = 123');
    }
}
Drag options to blanks, or click blank then click option'
APaymentDatabase
BOrderDatabase
CSharedDatabase
DGlobalDB
Attempts:
3 left
💡 Hint
Common Mistakes
Using another service's database directly causing tight coupling.
4fill in blank
hard

Fill both blanks to implement service communication without sharing databases.

Microservices
class InventoryService {
    constructor() {
        this.db = new [1]();
    }

    updateStock(orderId) {
        // Notify OrderService via [2]
        this.notifyOrderService(orderId);
    }
}
Drag options to blanks, or click blank then click option'
AInventoryDatabase
BDirectDBAccess
CMessageQueue
DSharedDatabase
Attempts:
3 left
💡 Hint
Common Mistakes
Using shared databases or direct DB access for communication.
5fill in blank
hard

Fill all three blanks to implement a microservice with isolated database and API communication.

Microservices
class ShippingService {
    constructor() {
        this.db = new [1]();
    }

    notifyOrderService(shippingId) {
        fetch(`http://orderservice/api/orders/[2]`, {
            method: '[3]',
            body: JSON.stringify({ shippingId })
        });
    }
}
Drag options to blanks, or click blank then click option'
AShippingDatabase
BupdateShippingStatus
CPOST
DSharedDB
Attempts:
3 left
💡 Hint
Common Mistakes
Using shared databases or incorrect HTTP methods.