Bird
Raised Fist0
Microservicessystem_design~10 mins

Dynamic configuration updates in Microservices - Interactive Code Practice

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 fetch the latest configuration from the config server.

Microservices
config = config_client.[1]('service-config')
Drag options to blanks, or click blank then click option'
Aget_config
Bretrieve_config
Cfetch_config
Dload_config
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get_config' which might be a local cache fetch, not from the server.
Using 'load_config' which implies loading from a file, not a remote server.
2fill in blank
medium

Complete the code to subscribe to configuration changes using the event listener.

Microservices
config_client.on('[1]', update_config_handler)
Drag options to blanks, or click blank then click option'
Aconfig_reload
Bconfig_change
Cconfig_update
Dconfig_refresh
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'config_update' which is less common as an event name.
Using 'config_reload' which is an action, not an event.
3fill in blank
hard

Fix the error in the code to reload configuration safely.

Microservices
if config_client.[1]():
    reload_configuration()
Drag options to blanks, or click blank then click option'
Aconfig_changed
Bis_updated
Chas_update
Dhas_new_config
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'has_new_config' which is not a standard method.
Using 'is_updated' which is ambiguous.
4fill in blank
hard

Fill both blanks to implement a cache invalidation after config update.

Microservices
def update_config_handler(event):
    config_client.[1]()
    cache.[2]()
Drag options to blanks, or click blank then click option'
Arefresh_config
Bclear_cache
Cinvalidate_cache
Dreload_config
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'refresh_config' which might not trigger a full reload.
Using 'clear_cache' which is valid but less precise than 'invalidate_cache'.
5fill in blank
hard

Fill all three blanks to implement a safe config update with version check and notification.

Microservices
def safe_update(new_config):
    if new_config.version [1] current_config.version:
        config_client.[2](new_config)
        notify_services('[3]')
Drag options to blanks, or click blank then click option'
A>
Bupdate_config
Cconfig_updated
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which would allow older versions to overwrite newer ones.
Using wrong event names that do not notify services properly.

Practice

(1/5)
1. What is the main benefit of using dynamic configuration updates in microservices?
easy
A. Encrypt all service communication by default
B. Change service settings without restarting or downtime
C. Reduce the size of service containers
D. Increase the number of microservices automatically

Solution

  1. Step 1: Understand dynamic configuration updates

    Dynamic configuration updates allow changing settings while the service is running.
  2. Step 2: Identify the main benefit

    This avoids restarting services, preventing downtime and improving flexibility.
  3. Final Answer:

    Change service settings without restarting or downtime -> Option B
  4. Quick Check:

    Dynamic config = no downtime updates [OK]
Hint: Dynamic config means no restart needed for changes [OK]
Common Mistakes:
  • Confusing dynamic config with scaling services
  • Thinking it reduces container size
  • Assuming it encrypts communication automatically
2. Which of the following is a common method for microservices to receive dynamic configuration updates?
easy
A. Polling a central configuration server periodically
B. Hardcoding config values in source code
C. Restarting the service every hour
D. Using static environment variables only

Solution

  1. Step 1: Review methods for dynamic config updates

    Common methods include polling or push from a central config server.
  2. Step 2: Identify the correct method

    Polling a config server lets services fetch updates regularly without restart.
  3. Final Answer:

    Polling a central configuration server periodically -> Option A
  4. Quick Check:

    Polling config server = dynamic updates [OK]
Hint: Dynamic config needs active update fetching, not static values [OK]
Common Mistakes:
  • Thinking hardcoded values can update dynamically
  • Assuming restart is needed for updates
  • Believing static env vars update automatically
3. Consider this pseudocode for a microservice fetching config updates:
config = load_config()
while True:
    if config_server.has_update():
        config = config_server.get_update()
    sleep(10)
    print(config['feature_flag'])
What will this code do when the feature_flag changes on the config server?
medium
A. Print the old feature_flag value forever
B. Crash because config_server.has_update() is undefined
C. Print nothing because of missing initial config
D. Update and print the new feature_flag value every 10 seconds

Solution

  1. Step 1: Analyze the update check loop

    The code checks if the config server has an update, then fetches it.
  2. Step 2: Understand the print behavior

    Every 10 seconds it prints the current feature_flag from the updated config.
  3. Final Answer:

    Update and print the new feature_flag value every 10 seconds -> Option D
  4. Quick Check:

    Polling loop updates config = prints new value [OK]
Hint: Polling loop updates config then prints latest value [OK]
Common Mistakes:
  • Assuming config never updates after initial load
  • Thinking code crashes due to undefined methods (assumed defined)
  • Ignoring the sleep and print inside the loop
4. A microservice uses a push-based config update system but sometimes misses updates. What is a likely cause?
medium
A. The service does not acknowledge receipt of updates
B. The service polls the config server too frequently
C. The service restarts after every update
D. The config server uses static environment variables

Solution

  1. Step 1: Understand push-based config update mechanism

    Push systems send updates and expect acknowledgments to confirm delivery.
  2. Step 2: Identify why updates are missed

    If the service does not acknowledge, the server may not resend or confirm updates.
  3. Final Answer:

    The service does not acknowledge receipt of updates -> Option A
  4. Quick Check:

    Missing ack = missed updates in push system [OK]
Hint: Push updates need acknowledgments to avoid missing data [OK]
Common Mistakes:
  • Confusing push with polling frequency issues
  • Assuming restarts cause missed updates
  • Thinking static env vars relate to push update failures
5. You design a microservices system with dynamic config updates using a central config server. To ensure minimal latency and high availability, which approach is best?
hard
A. Embed config in each service and restart services on config change
B. Use a single config server with clients polling every second
C. Deploy multiple config server replicas with push notifications and local caching
D. Use static config files updated manually on each service host

Solution

  1. Step 1: Consider latency and availability needs

    Multiple replicas reduce single points of failure and improve response times.
  2. Step 2: Evaluate update delivery methods

    Push notifications with local caching reduce latency and avoid constant polling.
  3. Final Answer:

    Deploy multiple config server replicas with push notifications and local caching -> Option C
  4. Quick Check:

    Replicas + push + cache = low latency & high availability [OK]
Hint: Replicas + push + cache = best for latency and availability [OK]
Common Mistakes:
  • Relying on single server causes downtime
  • Polling every second wastes resources
  • Restarting services causes downtime
  • Manual static updates are error-prone and slow