What is the default value for the Consul KV flags field if not provided during a write?
Flags defaults to 0.
Why this answer
The default value for flags is 0.
38 questions · Key Value Store topic · All types, answers revealed
What is the default value for the Consul KV flags field if not provided during a write?
Flags defaults to 0.
Why this answer
The default value for flags is 0.
Which Consul agent configuration parameter defines the KV store file location when running locally?
Consul stores all state data in the directory specified by data_dir.
Why this answer
While the KV store is in-memory, its persistence (if snapshots are used) is managed by the data_dir.
You need to perform a write operation to the Consul KV store that only succeeds if the current ModifyIndex of the key is zero. Which parameter should you include in your API call?
The cas parameter with a value of 0 is the standard way to perform a create-if-not-exists operation.
Why this answer
The cas (Check-And-Set) parameter allows for atomic operations. Setting cas to 0 ensures the write only occurs if the key does not already exist.
Which THREE of the following represent potential bottlenecks for Consul KV performance?
Massive key counts increase memory usage.
Why this answer
High update frequency, massive key counts, and large value sizes all impact KV performance.
You observe that a session lock is being released unexpectedly. What is the most likely cause?
If network latency prevents the renewal, the session expires.
Why this answer
If the session TTL is too short, the agent might fail to renew the session in time, causing it to expire.
What is the purpose of the 'Behavior' field when creating a Consul session?
The behavior field defines if locks are released or the key is deleted.
Why this answer
The behavior field determines what happens to locks when a session is invalidated; 'release' is the default, while 'delete' removes the key.
Which HTTP method is used to create or update a key in the Consul KV store?
PUT is used to write/update KV data.
Why this answer
The PUT method is the standard HTTP verb used for key creation and updates in the Consul API.
Which THREE of the following fields are returned in a typical Consul KV API GET response?
The index of the last modification is returned.
Why this answer
The Key, Value, and ModifyIndex are standard fields in the KV API response.
You are configuring a Consul Watch to trigger a script whenever a specific KV key changes. Which type of watch should you define in your configuration file?
Key watches track updates to a specific KV path.
Why this answer
The 'key' watch type is specifically designed to monitor changes to a single KV entry.
Which command-line interface command is used to set a value in the Consul KV store?
Put is the correct verb for setting values.
Why this answer
The 'consul kv put' command is the standard CLI utility for setting key values.
Which THREE of the following are true about Consul KV keys?
Values are base64 encoded, allowing binary.
Why this answer
Keys are organized in a hierarchy, they are case-sensitive, and they can store arbitrary data.
You want to delete a key and all its children in the KV store using the CLI. Which flag should you use?
-recurse allows recursive operations in the CLI.
Why this answer
The -recurse flag in the CLI allows the delete operation to act on the key and all nested keys.
Which Consul API endpoint is used to create a new session that can be used for locking KV keys?
This endpoint creates the session required for session-based locking.
Why this answer
The /v1/session/create endpoint is the standard way to initialize a session object in Consul.
When using the Consul KV store, what is the maximum size allowed for a single value in a key?
Consul limits the value size to 512 KB.
Why this answer
Consul enforces a hard limit of 512 KB per KV entry value.
When providing a session TTL, what is the minimum duration allowed?
The minimum is 10s.
Why this answer
The minimum session TTL allowed is 10 seconds.
What happens if you try to write to a key that is currently locked by a session you do not own?
Writes to locked keys require the matching session ID.
Why this answer
The write will be rejected if the session ID is not provided or if the session does not match the lock holder.
You need to ensure that a read operation from the KV store is strongly consistent. Which consistency mode should you specify?
Consistent forces a leader check for strong consistency.
Why this answer
The 'consistent' consistency mode forces the leader to verify its leadership with a quorum of peers, ensuring strong consistency.
Which flag can be used to pass arbitrary metadata to a KV entry?
Flags is the defined field for metadata.
Why this answer
The 'flags' field in the KV API allows users to store an unsigned integer for application-specific metadata.
Which THREE of the following are standard Consul KV CLI subcommands?
Used to create/update keys.
Why this answer
'put', 'get', and 'delete' are the standard CLI subcommands for KV.
Which TWO of the following are valid ways to trigger a KV watch?
Value updates trigger watches.
Why this answer
Watches can be triggered by a change in the KV value or a change in the ModifyIndex (which occurs on any write).
Which TWO of the following are true regarding Consul KV watches?
Watches are implemented using long polling.
Why this answer
Watches can be configured via agent configuration or the API, and they use blocking queries internally.
You are using a Consul Watch to monitor KV changes. What does the 'handler' field specify?
The handler is the command or script to run.
Why this answer
The handler field specifies the path to an executable that should be triggered when a change is detected.
When a session is associated with a lock, what happens to the lock if the session is deleted?
Session deletion triggers the release of associated locks.
Why this answer
Deleting a session immediately releases any locks associated with that session.
Which TWO of the following are true about the 'cas' parameter in KV writes?
Correct definition.
Why this answer
The 'cas' parameter stands for Check-And-Set and requires the index to be provided to ensure atomicity.
What happens to a session if the associated node is marked as 'failed' by the Consul health check?
Health check failure triggers the countdown for session invalidation.
Why this answer
When a node fails, the sessions associated with that node are invalidated after the session TTL expires.
You want to perform a blocking query on a KV key to watch for updates. Which parameter must you provide in your request based on the last observed index?
The index parameter specifies the last known index to block on.
Why this answer
The index parameter is used in the query string to inform Consul that you want to wait until the current state index is greater than the provided value.
When using Consul KV for distributed locking, why is it recommended to use a session?
This prevents orphaned locks.
Why this answer
Sessions provide a mechanism for TTL-based auto-release, which prevents deadlocks if an application crashes while holding a lock.
An application is using Consul KV to store configuration. You notice that the KV store is becoming large. What is the most efficient way to retrieve only the keys under the prefix "service/web/"?
Recurse=true returns all keys sharing the specified prefix.
Why this answer
The recurse parameter allows the KV API to return all keys with a matching prefix, rather than just the single key specified.
If a KV operation returns a 403 Forbidden status, what is the most common cause?
A 403 indicates a policy violation.
Why this answer
ACLs (Access Control Lists) are enabled, and the client token lacks the 'write' permission for that specific prefix.
You have implemented a leader election mechanism using Consul KV sessions. The session has a TTL of 15 seconds. If the application crashes, how long will it take for the lock to be automatically released?
The session TTL defines the duration after which an un-renewed session is invalidated, releasing associated locks.
Why this answer
When a session has a TTL, the lock is released when the session is invalidated by the health check failure. The default session invalidation is tied to the TTL.
If a Consul agent is configured with 'disable_remote_exec = true', how does this affect the KV store?
Remote exec and KV store are distinct features.
Why this answer
This setting does not impact the KV store; it only restricts the execution of remote commands via the Consul event system.
Which THREE of the following are valid session behaviors when a session is invalidated?
The lock remains held (if supported by specific implementation logic).
Why this answer
Consul sessions support 'release' (default), 'delete' (deletes the key), and no other behaviors. 'Release' is the standard behavior.
Which TWO of the following are true regarding the behavior of the Consul KV store?
Stale consistency mode permits non-leader reads.
Why this answer
KV values are stored as base64 encoded strings in the API, and they are eventually consistent for stale reads.
You need to retrieve the session information for a specific session ID. Which endpoint should you query?
This endpoint retrieves session metadata.
Why this answer
The /v1/session/info/:id endpoint returns the details of a specific session.
You want to perform a list operation on a KV prefix to see all keys, but you don't want the values returned. Which API parameter helps reduce payload size?
The keys parameter returns only the list of keys.
Why this answer
The 'keys' parameter can be used with a prefix to return only the list of key names, not their contents.
Which Consul feature allows you to observe the KV store for changes and run a command in response?
Watches trigger actions upon data changes.
Why this answer
Consul Watches are the built-in mechanism for reacting to changes in the KV store.
Which THREE of the following are required to successfully acquire a lock on a KV key?
The session ID is required to identify the locker.
Why this answer
To acquire a lock, you need a session, the key itself, and the acquire parameter in the API call.
Which TWO of the following are common use cases for the Consul KV store?
This is a core use case.
Why this answer
KV is primarily used for configuration management and distributed locking.
Ready to test yourself?
Try a timed practice session using only Key Value Store questions.