Bird
Raised Fist0
Microservicessystem_design~10 mins

Why good service boundaries prevent coupling in Microservices - Test Your Understanding

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. Why do good service boundaries help prevent tight coupling in microservices?
easy
A. They keep services independent by limiting direct data sharing.
B. They force all services to share the same database.
C. They require services to be written in the same programming language.
D. They make services depend on each other's internal code.

Solution

  1. Step 1: Understand service independence

    Good service boundaries mean each service manages its own data and logic without relying on others internally.
  2. Step 2: Recognize coupling causes

    Tight coupling happens when services share data directly or depend on each other's internal code, which good boundaries avoid.
  3. Final Answer:

    They keep services independent by limiting direct data sharing. -> Option A
  4. Quick Check:

    Service independence = prevents tight coupling [OK]
Hint: Good boundaries mean no direct data sharing between services [OK]
Common Mistakes:
  • Thinking services must share the same database
  • Believing services must use the same language
  • Assuming internal code sharing is allowed
2. Which of the following is the correct way for microservices to communicate to avoid tight coupling?
easy
A. Directly accessing each other's databases
B. Using well-defined APIs for communication
C. Sharing internal code libraries
D. Calling private functions inside other services

Solution

  1. Step 1: Identify communication methods

    Microservices should communicate through clear, public interfaces like APIs, not by accessing internals.
  2. Step 2: Evaluate options

    Only using well-defined APIs ensures loose coupling and clear contracts between services.
  3. Final Answer:

    Using well-defined APIs for communication -> Option B
  4. Quick Check:

    API communication = avoids tight coupling [OK]
Hint: Use APIs, not direct database or code access [OK]
Common Mistakes:
  • Choosing direct database access
  • Thinking code sharing is good
  • Calling private functions across services
3. Consider two microservices: OrderService and InventoryService. If OrderService directly queries InventoryService's database to check stock, what is the likely outcome?
medium
A. Tight coupling occurs, making changes risky and complex.
B. The services communicate through APIs efficiently.
C. The system automatically scales better.
D. Services remain loosely coupled and easy to update.

Solution

  1. Step 1: Analyze direct database access impact

    When one service accesses another's database, it creates a strong dependency on internal data structure.
  2. Step 2: Understand coupling consequences

    This tight coupling makes updates risky because changes in one service's database can break the other.
  3. Final Answer:

    Tight coupling occurs, making changes risky and complex. -> Option A
  4. Quick Check:

    Direct DB access = tight coupling [OK]
Hint: Direct DB access causes tight coupling and risks [OK]
Common Mistakes:
  • Assuming direct DB access improves scaling
  • Believing services stay loosely coupled
  • Confusing API communication with direct DB queries
4. A team notices their microservices are tightly coupled because they share a common database schema. What is the best way to fix this issue?
medium
A. Keep sharing the database but add more indexes.
B. Merge all services into one monolithic application.
C. Allow services to call each other's internal functions.
D. Split the shared database into separate databases per service.

Solution

  1. Step 1: Identify the cause of tight coupling

    Sharing a database schema tightly couples services because they depend on the same data structure.
  2. Step 2: Choose the best fix

    Splitting the database per service enforces boundaries and independence, reducing coupling.
  3. Final Answer:

    Split the shared database into separate databases per service. -> Option D
  4. Quick Check:

    Separate databases = better service boundaries [OK]
Hint: Separate databases per service reduce coupling [OK]
Common Mistakes:
  • Merging services increases coupling
  • Calling internal functions breaks boundaries
  • Adding indexes doesn't fix coupling
5. You are designing a microservices system for an online store. To prevent tight coupling, which approach best defines service boundaries?
hard
A. Services share internal code libraries to reuse logic.
B. All services share a single database to simplify data access.
C. Each service owns its data and exposes only APIs; no direct data sharing.
D. Services call each other's private methods for faster communication.

Solution

  1. Step 1: Define good service boundaries

    Good boundaries mean each service manages its own data and communicates only through APIs.
  2. Step 2: Evaluate options for coupling

    Sharing databases or internal code increases coupling; calling private methods breaks encapsulation.
  3. Final Answer:

    Each service owns its data and exposes only APIs; no direct data sharing. -> Option C
  4. Quick Check:

    Own data + APIs = loose coupling [OK]
Hint: Own data + APIs = best boundaries [OK]
Common Mistakes:
  • Sharing a single database
  • Reusing internal code across services
  • Calling private methods between services