Courseiva

CCNA Key Value Store Questions

57 questions · Key Value Store · All types, answers revealed

1
MCQmedium

An operator wants to list every key beneath the `services/web/` prefix, including nested paths, and see each key's associated flags and modify index. Which command returns that information?

A.consul catalog services services/web/
B.consul kv get services/web/
C.consul kv export services/web/
D.consul kv get -recurse services/web/
AnswerD

The `-recurse` flag makes the get operation return every key sharing the given prefix, including nested paths, along with each key's value, flags, and modify index. This single command satisfies the requirement to enumerate the subtree and inspect metadata for each entry, which is why it is the standard way to audit a KV prefix.

Why this answer

Listing a KV subtree with metadata requires recursion. The `-recurse` flag on `consul kv get` returns every key under the prefix, each with its value, flags, and modify index, which is precisely the audit view the operator needs. A non-recursive get targets a single key, export targets backup workflows, and the catalog command serves a different subsystem.

Exam trap

The trap here is assuming that passing a prefix to a plain get returns the subtree, when Consul only enumerates children when recursion is explicitly requested.

2
MCQeasy

What is the default value for the Consul KV flags field if not provided during a write?

A.1
B.null
C.0
D.-1
AnswerC

Consul's KV write API defaults the Flags field to 0 when the request omits it. Flags is an opaque 64-bit unsigned integer reserved for client-side use, so Consul stores zero rather than rejecting the write.

Why this answer

When a KV pair is written without specifying the flags field, Consul defaults the flags value to 0. The flags field is a 64-bit unsigned integer used for application-specific metadata, and its zero value indicates no flags set.

Exam trap

The trap is assuming flags defaults to null or 1 because it is optional metadata; candidates forget that Consul uses a zero-value integer default for unset numeric fields.

How to eliminate wrong answers

Option A is wrong because 1 is not a default — it would imply a specific flag bit is set, which Consul does not assume. Option B is wrong because null is not a valid value for the flags field; Consul stores it as an integer, not a nullable type. Option D is wrong because -1 is not valid for an unsigned 64-bit integer and is not the default.

3
MCQmedium

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?

A.acquire=0
B.cas=0
C.flags=0
D.index=0
AnswerB

Consul's check-and-set parameter makes the write conditional on the key's current ModifyIndex. Supplying cas=0 means the operation succeeds only when the key does not yet exist, since a fresh key has ModifyIndex zero. Any existing key returns a conflict, satisfying the stem's requirement exactly.

Why this answer

The Consul KV write API supports a 'cas' (Check-And-Set) parameter that performs an atomic compare-and-swap against the key's ModifyIndex. Setting cas=0 means the write only succeeds if the key does not currently exist (ModifyIndex is zero), which is the standard way to implement create-if-not-exists semantics.

Exam trap

Consul 1.15 often tests the difference between 'cas' (compare-and-swap on ModifyIndex) and 'acquire' (session-based lock acquisition) — candidates confuse the two because both are conditional write parameters.

How to eliminate wrong answers

Option A is wrong because 'acquire' is used with Consul sessions to acquire a lock on a key, not to compare against ModifyIndex. Option C is wrong because 'flags' is an opaque unsigned integer stored alongside the KV pair for client use and has no role in conditional writes. Option D is wrong because 'index' is a blocking-query parameter used on reads to wait for changes beyond a given index, not a write precondition.

4
MCQmedium

A security team stores application secrets under the Consul KV prefix `app/prod/`. They want to be notified whenever any key under that prefix changes, without repeatedly polling the entire prefix. They have access to the Consul HTTP API and the `consul watch` command. Which approach should they use?

A.Use `consul watch -type=checks -service=app` to monitor the health of the application service.
B.Use `consul watch -type=keyprefix -prefix=app/prod/` to monitor all keys under the prefix.
C.Use `consul watch -type=event -name=app/prod/` to watch for custom events with that name.
D.Use `consul watch -type=key -key=app/prod/` to monitor the prefix as a single key.
AnswerB

The `consul watch` command supports the `keyprefix` watch type, which monitors all keys under a given prefix. When any key under `app/prod/` is added, modified, or deleted, the watch fires and returns the current state of the prefix. This avoids polling and efficiently notifies the team of any change.

Why this answer

The `keyprefix` watch type is designed to monitor all keys under a given prefix and trigger notifications on any change. It uses blocking queries internally, so it is efficient and immediate. The other watch types target single keys, health checks, or events, none of which would detect changes across the entire `app/prod/` prefix.

Exam trap

The trap here is confusing the `key` watch type with the `keyprefix` watch type, assuming that specifying a prefix with `key` will automatically monitor all nested keys.

5
MCQhard

A platform team stores service configuration under the Consul KV prefix `config/web/`. An operator runs `consul kv put config/web/timeout 30` at a time when the key already exists with value `45` and ModifyIndex `812`. The operator later needs to update the value only if no one else has changed the key since that write. Which Consul CLI invocation correctly performs this compare-and-swap using the index returned by the prior write?

A.consul kv put -index=812 config/web/timeout 60
B.consul kv put -cas=812 config/web/timeout 60
C.consul kv put -lock=812 config/web/timeout 60
D.consul kv put -modify-index=812 config/web/timeout 60
AnswerB

The `-cas` flag performs a check-and-set using the supplied ModifyIndex. Passing `812`, the index observed from the prior read or write, tells Consul to apply the new value only if the key's current ModifyIndex still equals 812. If another client changed the key in the meantime, Consul returns HTTP 409 Conflict and the write is rejected, which is exactly the compare-and-swap behavior required here.

Why this answer

Consul KV supports optimistic concurrency through the check-and-set parameter, exposed on the CLI as `-cas`. Supplying the ModifyIndex observed from a previous operation makes the write succeed only when the key has not been modified since that index was read. If any other client wrote to the key in between, Consul rejects the update with a conflict, letting the operator re-read and retry rather than silently overwriting another change.

Exam trap

The trap here is assuming any index-like flag can make a KV write conditional, when only the check-and-set parameter compares the supplied index against the key's current ModifyIndex.

6
MCQhard

A team stores rolling deployment state under `deploy/current`. To avoid a race where two operators both believe they own the release, the application must acquire the key only if it is not already held, and it must automatically release the key if the holding process dies. Which combination of Consul primitives achieves this?

A.Use consul kv put with the -cas flag set to the current ModifyIndex on every write attempt.
B.Create a session, then call the KV acquire endpoint with that session and the key; the lock is released automatically when the session expires.
C.Write the key with consul kv put, then poll the key every second to detect a competing writer.
D.Register a service check for the operator and rely on the catalog health status to block duplicate writes.
AnswerB

Acquire is atomic and succeeds only when the key is unheld or already held by the same session. Binding the key to a session means Consul releases it when the session is invalidated, whether by TTL expiry or a failed health check, giving automatic release on process death.

Why this answer

Mutual exclusion with automatic release requires a session-bound acquisition. The acquire operation is atomic, so only one session can hold the key, and because the key is tied to a session it is freed when that session ends. This pairs contention safety with failure recovery, which plain writes or check-and-set alone cannot provide.

Exam trap

The trap here is assuming check-and-set alone provides locking, when it only prevents lost updates and never releases a key after a process dies.

7
Multi-Selecthard

Which THREE of the following represent potential bottlenecks for Consul KV performance?

Select 3 answers
A.Very large number of keys
B.Very high write throughput
C.High read frequency
D.Very large value sizes
E.Using HTTP instead of RPC
AnswersA, B, D

A very large number of keys inflates the key space that Consul must track, replicate and index across servers, raising memory pressure and Raft log overhead. This directly bottlenecks KV performance, since every write must be consistently replicated to the cluster's followers.

Why this answer

Option A is correct because Consul's KV store keeps all keys in memory and replicates them via Raft, so a very large number of keys increases memory pressure, snapshot size, and Raft log/replication overhead, degrading performance. Option B is correct because every KV write must be committed through the Raft consensus protocol and replicated to a quorum of servers, so very high write throughput becomes a bottleneck as the leader serializes and replicates each write. Option D is correct because very large value sizes inflate Raft log entries, snapshot transfers, and network replication traffic, and Consul enforces a maximum KV value size (512 KB) precisely because oversized values harm performance.

Option C is not a primary bottleneck because reads can be served by any server (including non-leaders) and stale reads can be served locally, so high read frequency scales better than writes. Option E is not a bottleneck because HTTP is the standard Consul KV API transport and the RPC layer is used internally; the protocol choice itself is not a performance-limiting factor compared to key count, write volume, and value size.

Exam trap

Consul 1.15 often tests whether candidates misidentify read frequency or transport protocol as bottlenecks, when the real constraints are write volume, key count, and value size on the Raft-replicated store.

8
MCQhard

An operator needs to update the value of `config/database/url` in Consul KV, but only if the current value is exactly `postgres://old:5432`. They want to use the Consul CLI to perform a compare-and-swap operation. Which command should they use?

A.consul kv put -cas=123 config/database/url postgres://new:5432
B.First retrieve the current ModifyIndex of `config/database/url` and verify the value is `postgres://old:5432`, then use `consul kv put -cas=<index> config/database/url postgres://new:5432`.
C.consul kv put -cas -value=postgres://old:5432 config/database/url postgres://new:5432
D.consul kv put -cas -modify-index=123 config/database/url postgres://new:5432
AnswerB

Consul's compare-and-swap is based on the ModifyIndex, not the value. To ensure the value is as expected, the operator must first read the key to check its value and obtain its ModifyIndex, then use `-cas` with that index. If the key changes between the read and the write, the CAS operation fails, preventing race conditions.

Why this answer

Consul KV does not support value-based compare-and-swap directly. The `-cas` flag uses the ModifyIndex to ensure atomic updates. The correct approach is to read the key, verify the value, and then use the ModifyIndex with `-cas`.

This prevents lost updates if another client modifies the key in between.

Exam trap

The trap here is assuming Consul's CAS operation compares the value itself, when it actually compares the ModifyIndex.

9
MCQhard

You observe that a session lock is being released unexpectedly. What is the most likely cause?

A.The Consul agent is in leader mode.
B.The index was not incremented.
C.The session TTL is too low, causing premature expiration.
D.The KV key was deleted.
AnswerC

A session lock is released when its TTL elapses, so a TTL set too low expires the session prematurely and frees the lock without any explicit release call. This directly satisfies the stem's unexpected-release constraint: Consul's lock is tied to session lifetime, not to client intent.

Why this answer

Consul sessions are tied to a TTL (Time-To-Live) that must be periodically renewed by the owning agent. If the TTL is set too low and the agent fails to renew in time—due to network latency, agent overload, or misconfiguration—the session expires, and any locks held by that session are automatically released. This is the most common cause of unexpected lock releases in Consul.

Exam trap

Consul 1.15 often tests the misconception that session locks are released only when the key is deleted or the agent crashes, but the most common cause is TTL expiration due to missed renewals.

How to eliminate wrong answers

Option A is wrong because leader mode is a property of the Consul server cluster (Raft leader), not a client agent; an agent being in leader mode does not affect session locks. Option B is wrong because the index is a monotonically increasing value used for blocking queries and consistency; it does not cause session expiration or lock release. Option D is wrong because deleting the KV key would remove the lock entry, but the question asks about the lock being released, which implies the session ended; key deletion is a separate action and not the most likely cause of an unexpected release.

10
MCQmedium

What is the purpose of the 'Behavior' field when creating a Consul session?

A.To specify what happens to locks on session invalidation.
B.To define the node affinity.
C.To determine if the session can be renewed.
D.To set the session priority.
AnswerA

The Behaviour field controls session invalidation semantics, determining whether locks held by the session are released or remain, directly answering what happens to locks when a session becomes invalid. This governs the release behaviour rather than lock acquisition.

Why this answer

The 'Behavior' field in a Consul session controls what happens to locks held by the session when the session is invalidated (e.g., due to TTL expiry or explicit destruction). The two valid values are 'release' (default), which releases all locks, and 'delete', which deletes the locks. This determines the fate of held locks upon session invalidation.

Exam trap

Consul 1.15 often tests the specific purpose of the Behavior field, and candidates may confuse it with session renewal or node affinity, when it actually controls lock handling on session invalidation.

How to eliminate wrong answers

Option B is wrong because node affinity is not controlled by the Behavior field — it is determined by the session's node and service checks. Option C is wrong because session renewal is governed by the TTL and the session's renewability, not the Behavior field. Option D is wrong because session priority is not a configurable field in Consul sessions.

11
MCQeasy

A developer needs to remove an obsolete configuration key `app/legacy/timeout` from Consul's KV store so the application no longer reads it. Which command deletes this single key?

A.consul kv delete app/legacy/timeout
B.consul kv put app/legacy/timeout ""
C.consul kv get app/legacy/timeout
D.consul kv export app/legacy/timeout
AnswerA

`consul kv delete` removes the specified key from the KV store. Given the exact path, it deletes only that key, which is precisely what the developer needs to stop the application from reading the obsolete timeout value. This is the direct, idiomatic way to remove a single key.

Why this answer

Removing a specific key is done with `consul kv delete` pointed at the exact path. That command eliminates the entry so the application stops seeing the obsolete timeout. Reading, overwriting with an empty value, or exporting the key all leave it in place, so none of them achieve the intended removal.

Exam trap

The trap here is assuming that writing an empty value deletes a key, when Consul keeps the key present with a zero-length value until it is explicitly deleted.

12
MCQmedium

A developer stores a feature flag at the key `config/features/new-ui` in Consul KV and wants to atomically create it only if it does not already exist, failing the write if the key is present. Which Consul CLI command accomplishes this?

A.consul kv put -flags=0 config/features/new-ui true
B.consul kv put -cas=0 config/features/new-ui true
C.consul kv put -acquire config/features/new-ui true
D.consul kv put -modify-index=0 config/features/new-ui true
AnswerB

The `-cas` flag performs a check-and-set operation. Passing `-cas=0` tells Consul to only write the key if its current ModifyIndex is 0, which is the case for a key that does not exist. If the key is already present, the write fails with a conflict, achieving the atomic create-if-absent behavior the developer needs.

Why this answer

Atomic create-if-absent writes in Consul KV are performed with the check-and-set flag. Supplying a CAS value of zero conditions the write on the key not yet existing, because a missing key reports a ModifyIndex of zero. If another client created the key first, its ModifyIndex becomes non-zero and the conditional write returns an error rather than overwriting it.

Exam trap

The trap here is assuming that a plain `consul kv put` is create-only or that `-flags` enforces uniqueness, when in fact only the `-cas` parameter provides conditional write behavior.

13
MCQeasy

An operator needs to delete the single KV entry `app/temp/cache-ttl` but must leave every other key under `app/temp/` untouched. Which command performs exactly that deletion?

A.consul kv delete -cas=0 app/temp/cache-ttl
B.consul kv delete -recurse app/temp/
C.consul kv put app/temp/cache-ttl ""
D.consul kv delete app/temp/cache-ttl
AnswerD

Supplying the full key path without any recursion flag deletes only that exact entry. Consul treats the argument as a literal key, so sibling keys under `app/temp/` remain intact. This is the precise, least-destructive command for removing one entry while preserving the rest of the prefix.

Why this answer

Deleting a single KV entry requires passing its full path to `consul kv delete` with no recursion flag. Consul then removes only that exact key, leaving all siblings under the same prefix intact. Recursion, check-and-set conditions, and empty-value writes all change behavior in ways that either over-delete, fail, or merely blank the value.

Exam trap

The trap here is confusing deletion with writing an empty value, since a zero-length write leaves the key present and visible to reads and watches.

14
MCQmedium

A developer uses the Consul KV store to coordinate a rolling deployment. They write a key `deploy/status` with the value `in-progress` using `consul kv put deploy/status in-progress`. Later, they want to check the current value of that key without any blocking or long-polling behavior. Which command should they run?

A.consul kv put deploy/status
B.consul kv get deploy/status
C.consul kv export deploy/status
D.consul watch -type=key -key=deploy/status
AnswerB

The `consul kv get` subcommand retrieves the value of a single key from the Consul KV store. It returns the value, and optionally metadata such as flags and CreateIndex/ModifyIndex when using `-detailed`. This directly answers the developer's need to read the current value of `deploy/status` without blocking or watch behavior, making it the correct choice.

Why this answer

The correct command is the one that performs a simple read of a single key. `consul kv get` retrieves the value and optional metadata for the specified key, matching the developer's requirement to check the current value without blocking. The other commands either write, watch, or export data, none of which satisfy a straightforward read.

Exam trap

The trap here is confusing a read operation with a watch or export, which may also display the key but do not provide a simple one-shot value retrieval.

15
MCQmedium

A platform team stores feature-flag values under the prefix `config/features/`. They need to read the single key `config/features/checkout` and receive its value along with metadata such as `CreateIndex` and `ModifyIndex` in the response. Which Consul CLI command accomplishes this?

A.consul kv put config/features/checkout
B.consul kv delete config/features/checkout
C.consul kv export config/features/checkout
D.consul kv get config/features/checkout
AnswerD

The `consul kv get` command retrieves a single key and, by default, returns the value plus metadata fields like CreateIndex, ModifyIndex, LockIndex, Flags, and Session. Because the request targets one exact key path, the response includes that key's metadata without needing any extra flag such as `-detailed`, which is only required for listing operations.

Why this answer

Reading one exact key path with `consul kv get` returns the stored value together with the key's metadata, including CreateIndex and ModifyIndex, which the team needs for change tracking. The other commands either modify or delete the key or export a prefix in a different JSON format, so they cannot deliver a single-key read with its index fields.

Exam trap

The trap here is assuming that metadata such as CreateIndex only appears when listing keys with a recursive flag, when in fact a direct single-key read already includes it.

16
MCQmedium

You are using a Consul KV entry to store a feature flag. You want the flag to be automatically deleted if the node that owns it becomes unhealthy. Which Consul API operation should you use?

A.Call PUT /v1/kv/feature/flag?cas=0 with the flag value, then configure a watch to delete the key when the node fails.
B.Call PUT /v1/kv/feature/flag?flags=1 with the flag value, then rely on Consul's garbage collector to remove it when the node fails.
C.Create a session with the node's checks, then call PUT /v1/kv/feature/flag?acquire=<session> with the flag value.
D.Call PUT /v1/kv/feature/flag?release=<session> with the flag value, then create a session for the node.
AnswerC

Acquiring a KV key with a session creates a lock. If the session is invalidated—for example, because the node's health check fails—Consul automatically releases the lock and deletes the key. This directly ties the flag's lifetime to the node's health, matching the requirement.

Why this answer

Acquiring a KV entry with a session establishes a lock. When the session's health checks fail, Consul invalidates the session and releases the lock, deleting the key. This is the intended mechanism for tying a KV entry's lifetime to node health.

The other operations either set metadata, perform conditional writes, or attempt to release a lock that was never acquired.

Exam trap

The trap here is confusing the flags or cas query parameters with session-based locking, which is the only way to make a KV entry automatically delete when a node becomes unhealthy.

17
MCQeasy

Which HTTP method is used to create or update a key in the Consul KV store?

A.GET
B.PUT
C.DELETE
D.POST
AnswerB

Consul's KV store uses PUT to create or update a key, since the operation is idempotent and supplies the value in the request body. POST is not used for KV writes, satisfying the stem's create-or-update requirement.

Why this answer

The Consul KV store uses the PUT HTTP method to create or update a key. A PUT to /v1/kv/<key> with the value in the request body either creates the key if it does not exist or overwrites it if it does, making PUT the idempotent write operation for KV entries.

Exam trap

The trap is assuming POST is the generic 'create' verb for REST APIs; Consul specifically uses PUT for KV writes, and candidates who default to POST without checking the API reference will miss this.

How to eliminate wrong answers

Option A is wrong because GET is a read-only method used to retrieve the value of an existing key, not to create or modify it. Option C is wrong because DELETE removes a key or recursively removes a key prefix, which is the opposite of creating or updating. Option D is wrong because POST is not the documented method for writing KV values in Consul; while POST is used for other Consul API operations like registering services, KV writes specifically use PUT.

18
MCQhard

You are implementing a distributed semaphore using Consul KV and sessions. You create a session with a TTL of 60 seconds and use the 'acquire' parameter to lock a key. After acquiring the lock, the application holding the session experiences a 90-second pause due to a garbage collection stop-the-world event. The Consul agent on the node is healthy and continues to renew the session. What happens to the lock?

A.The lock is released because the session TTL expires after 60 seconds without renewal from the application.
B.The lock is released immediately when the garbage collection pause begins because Consul detects the application is unresponsive.
C.The lock remains held because the Consul agent renews the session, and the application's pause does not affect the session.
D.The lock is released after 90 seconds when the application resumes and fails to renew the session in time.
AnswerC

The session is kept alive by the Consul agent's renewals. The application's pause does not impact the session because the agent operates independently. The lock remains held until the session is explicitly destroyed or the agent fails to renew. This is a common pitfall in distributed locking with Consul: the lock can outlive the application process.

Why this answer

Session TTL renewal is handled by the Consul agent, not the application. Even if the application is paused, the agent continues to renew the session, keeping the lock held. This can lead to a situation where a lock is held by a session whose application is not actively using it.

To avoid this, applications should explicitly release locks or use health checks that reflect application liveness.

Exam trap

The trap here is assuming that the application is responsible for renewing the session TTL, when in fact the Consul agent performs this task independently.

19
Multi-Selectmedium

Which THREE of the following fields are returned in a typical Consul KV API GET response?

Select 3 answers
A.ModifyIndex
B.Key
C.Value
D.SessionTTL
E.CreateTime
AnswersA, B, C

ModifyIndex is the raft index of the last modification to that key, returned alongside CreateIndex, LockIndex, Key, Flags and Value. It satisfies the stem's requirement by being a field the Consul KV API genuinely includes in its GET response.

Why this answer

A Consul KV API GET response (e.g., GET /v1/kv/<key>) returns a JSON array of entries containing the fields Key, Value, Flags, CreateIndex, ModifyIndex, LockIndex, and Session. Option A (ModifyIndex) is correct because it is the index at which the key was last modified and is included in every KV read response. Option B (Key) is correct because the full key path is returned so the client knows which key the entry corresponds to.

Option C (Value) is correct because the base64-encoded value stored at the key is returned (null if the key has no value). Option D (SessionTTL) is not part of the KV response; TTL is a property of sessions (returned by the session API, e.g., /v1/session/info), not of KV entries. Option E (CreateTime) is not a Consul KV field; Consul uses CreateIndex (a Raft index) rather than a timestamp to record when the key was created.

Exam trap

Consul 1.15 often tests whether candidates confuse raft index fields (CreateIndex, ModifyIndex) with timestamp fields (CreateTime), and whether they mistakenly attribute session properties like SessionTTL to KV entries.

20
MCQmedium

A team wants to store structured configuration for several microservices in Consul's KV store and retrieve an entire service's configuration with a single CLI call. They plan to keep all keys for `payments` under `services/payments/`. Which command retrieves every key under that prefix in one invocation?

A.consul kv get services/payments/
B.consul kv get -recurse services/payments/
C.consul kv put -recurse services/payments/
D.consul kv export services/payments/
AnswerB

The `-recurse` flag makes `consul kv get` walk every key beneath the given prefix and return them all in one response. This lets the team fetch the entire `payments` configuration set with a single call, which is exactly the prefix-retrieval behavior they need for loading structured config at startup.

Why this answer

Listing all keys under a prefix requires the recursive read behavior. Passing `-recurse` to `consul kv get` returns every key beneath the specified path in a single call, which is precisely how a service loads its whole configuration subtree. A trailing slash alone does nothing, and the other commands either write data or produce a backup-oriented export format.

Exam trap

The trap here is believing that appending a trailing slash to a key path automatically enumerates the subtree, when Consul instead requires the explicit `-recurse` flag.

21
MCQhard

An operator wants to atomically create a key `locks/leader` only if it does not already exist, so that two competing processes cannot both become leader. Which Consul KV operation should be used?

A.A `consul kv put` using the `-cas` flag set to 0
B.A normal `consul kv put` with no extra flags
C.A `consul kv get` followed by a `consul kv put`
D.A `consul kv put` with the `-flags` option set to a unique value
AnswerA

The `-cas` flag performs a check-and-set operation: the write succeeds only if the key's current ModifyIndex matches the supplied value. Passing 0 asserts that the key does not yet exist, so the first process to write wins and the second receives a failure. This gives the atomic create-if-absent behavior needed to elect a single leader without a race.

Why this answer

Atomic create-if-absent is achieved with the check-and-set mechanism. Supplying `-cas 0` tells Consul to perform the write only when the key's ModifyIndex is zero, meaning the key is absent. The first writer succeeds; any later writer sees a non-zero index and is rejected, ensuring a single leader without a race condition.

Exam trap

The trap here is treating a read-then-write sequence as safe, when only the `-cas` check-and-set flag provides the atomic guarantee Consul actually enforces.

22
MCQmedium

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?

A.event
B.service
C.key
D.nodes
AnswerC

A key watch monitors a single KV pair path and fires its handler whenever that key's value changes, matching the requirement to trigger a script on one specific key. Other watch types cover prefixes, services, nodes or checks, not individual key modification.

Why this answer

The 'key' watch type in Consul is specifically designed to monitor a single KV pair for changes. When the value of the specified key changes, the watch triggers the configured handler (e.g., a script). This matches the requirement of triggering a script whenever a specific KV key changes.

Other watch types monitor different Consul resources such as events, services, or nodes, and are not suited for tracking a single KV key.

Exam trap

Consul 1.15 often tests the distinction between watch types and their target resources; candidates may confuse 'key' with 'service' or 'event' watches, especially if they overlook that KV watches are specifically for key-value pairs.

How to eliminate wrong answers

Option A is wrong because an 'event' watch monitors Consul's event system (user events or internal events like leader election), not KV changes. Option B is wrong because a 'service' watch monitors the health and instances of a specific service, not KV data. Option D is wrong because a 'nodes' watch monitors the list of nodes in the catalog, not KV pairs.

23
MCQeasy

Which command-line interface command is used to set a value in the Consul KV store?

A.consul kv write
B.consul kv set
C.consul kv update
D.consul kv put
AnswerD

The consul kv put command writes a key-value pair into the Consul KV store, taking the key path and value as arguments. Other kv subcommands such as get, delete or export read or remove entries, so put is the correct write operation.

Why this answer

The correct Consul CLI command to set a value in the KV store is 'consul kv put'. This command writes a value to the specified key path. For example, 'consul kv put mykey myvalue' stores 'myvalue' at the key 'mykey'.

The other commands do not exist in the Consul CLI.

Exam trap

The trap is assuming that the command follows a common pattern like 'set' or 'write' from other key-value stores; candidates must remember that Consul uses 'put' for writing to the KV store, and the other verbs are not valid.

How to eliminate wrong answers

Option A is wrong because 'consul kv write' is not a valid Consul CLI command; the correct verb is 'put'. Option B is wrong because 'consul kv set' is not a valid command; Consul uses 'put' for writing values. Option C is wrong because 'consul kv update' is not a valid command; while there is a 'consul kv put' with a '-cas' flag for check-and-set, the base command is 'put'.

24
Multi-Selecteasy

Which THREE of the following are true about Consul KV keys?

Select 3 answers
A.Keys must start with a slash
B.Keys support storing binary data
C.Keys are case-sensitive
D.Keys cannot contain spaces
E.Keys can be organized in a folder-like hierarchy
AnswersB, C, E

Consul KV values are stored as raw byte arrays rather than text-only strings, so arbitrary binary payloads survive intact. This satisfies the stem's requirement, letting operators store certificates, images or serialised blobs directly without encoding them first.

Why this answer

Option B is correct because Consul KV values are stored as raw bytes, so any binary data (not just UTF-8 text) can be written and retrieved via the KV API or `consul kv put`/`consul kv get`. Option C is correct because Consul KV keys are case-sensitive, meaning `App/Config` and `app/config` are distinct keys. Option E is correct because keys use slash-delimited paths such as `service/web/port`, giving a folder-like hierarchy that can be listed with `consul kv get -recurse` or the `?recurse` API parameter.

Option A is wrong because a leading slash is not required; keys like `foo/bar` are valid without one. Option D is wrong because spaces are permitted in Consul KV keys (they are just bytes in the key string), so there is no rule forbidding them.

Exam trap

The trap is assuming KV keys follow filesystem rules like requiring a leading slash or disallowing spaces — candidates often over-apply Unix path conventions, but Consul KV keys are flexible byte strings with only case-sensitivity and hierarchy via slashes as notable properties.

25
MCQmedium

You want to delete a key and all its children in the KV store using the CLI. Which flag should you use?

A.-force
B.-recurse
C.--all
D.--cascade
AnswerB

The -recurse flag makes the delete operation walk the key's entire subtree, removing the key and every child beneath it in one command. Without it, Consul deletes only the single key, leaving children orphaned, so this satisfies the requirement to remove the key and all its children.

Why this answer

The -recurse flag in the CLI allows the delete operation to act on the key and all nested keys.

26
MCQmedium

Which Consul API endpoint is used to create a new session that can be used for locking KV keys?

A./v1/kv/acquire
B./v1/session/create
C./v1/lock/init
D./v1/session/renew
AnswerB

Consul creates lock sessions through the session endpoint, which returns a session ID used as the lock-delimiter when acquiring KV locks. The /v1/session/create path is the documented API for this, unlike destroy or renew operations.

Why this answer

The correct endpoint is /v1/session/create because it is specifically designed to create a new session in Consul. Sessions are the foundation for distributed locks and KV key acquisition. When you create a session, Consul returns a session ID that can be used with the KV acquire endpoint to obtain a lock on a key.

This endpoint accepts parameters like name, TTL, and behavior on invalidation, allowing fine-grained control over lock semantics.

Exam trap

Consul 1.15 often tests the distinction between session creation and KV lock acquisition, so candidates may confuse /v1/kv/acquire with /v1/session/create, forgetting that a session must exist before a lock can be acquired.

How to eliminate wrong answers

Option A is wrong because /v1/kv/acquire is used to acquire a lock on a KV key using an existing session, not to create a new session. Option C is wrong because /v1/lock/init does not exist in Consul's API; it is a fabricated endpoint. Option D is wrong because /v1/session/renew is used to renew an existing session's TTL, not to create a new session.

27
MCQmedium

You are deploying a blue/green release where the active environment is selected by the value of the Consul KV key `deploy/active-color`, currently set to `blue`. Your CI pipeline must atomically switch the value to `green` but only if the current value is still `blue`, and must fail if another pipeline already changed it. Which API operation should the pipeline use?

A.A `PUT` to `/v1/txn` that writes the new value and deletes the old one in the same transaction, using the key name as the version token.
B.A `PUT` to `/v1/kv/deploy/active-color` after acquiring a Consul session lock on the same key using `/v1/kv/deploy/active-color?acquire=<session>`.
C.A `PUT` to `/v1/kv/deploy/active-color?flags=1` with the body `green`, relying on the flags bit to reject concurrent writers.
D.A `PUT` to `/v1/kv/deploy/active-color` with the `cas` query parameter set to the `ModifyIndex` of the current `blue` value.
AnswerD

The check-and-set (`cas`) parameter makes the write succeed only when the key's current `ModifyIndex` equals the supplied value. Reading the key first to capture that index, then writing with `cas`, gives the pipeline an atomic compare-and-swap that fails if another pipeline already changed the value, exactly the guard the blue/green switch requires.

Why this answer

Atomic conditional writes in Consul KV are performed with the check-and-set mechanism: the client reads the key to learn its `ModifyIndex`, then issues a write carrying that index in the `cas` parameter. If the stored index no longer matches, the write is rejected and the pipeline knows another actor modified the key. This gives exactly the fail-if-changed semantics a blue/green switch needs.

Exam trap

The trap here is assuming the `flags` field or a session lock provides optimistic concurrency control on the value itself, when only the `cas` parameter compares the stored `ModifyIndex`.

28
MCQeasy

When using the Consul KV store, what is the maximum size allowed for a single value in a key?

A.There is no limit.
B.128 KB
C.1 MB
D.512 KB
AnswerD

Consul's KV store caps each individual value at 512 KB, a hard limit imposed by the Raft replication and storage layer. Larger payloads must be split across multiple keys or stored externally, so 512 KB is the precise maximum for a single key's value.

Why this answer

The Consul KV store enforces a maximum value size of 512 KB per key. This limit is a hard constraint imposed by the Raft consensus protocol, which replicates all writes across the cluster. Values larger than 512 KB are rejected by the server to prevent excessive memory usage and network overhead during replication.

This is documented in the official Consul limits and is consistent across versions, including 1.15.

Exam trap

The trap here is assuming that Consul KV has no size limit or confusing it with other systems that allow larger values, leading candidates to overlook the documented 512 KB maximum.

How to eliminate wrong answers

Option A is wrong because Consul does impose a hard limit on KV value size; claiming no limit is a misconception that ignores Raft's replication constraints. Option B is wrong because 128 KB is not the maximum; it is smaller than the actual limit and may be confused with other systems' defaults. Option C is wrong because 1 MB exceeds the actual limit; Consul rejects values larger than 512 KB, so 1 MB is not allowed.

29
MCQmedium

When providing a session TTL, what is the minimum duration allowed?

A.10 seconds
B.30 seconds
C.5 seconds
D.1 second
AnswerA

A session TTL of 10 seconds is the minimum Consul permits; any lower value is rejected. This satisfies the stem's constraint by matching Consul's documented lower bound for session TTLs, ensuring the lock-delay and health-check timing mechanisms retain meaningful granularity rather than collapsing into effectively immediate expiry.

Why this answer

Consul enforces a minimum session TTL of 10 seconds; any value below this is rejected by the agent. This floor prevents excessively chatty heartbeat traffic that would overwhelm the gossip protocol and server resources. The correct answer is therefore 10 seconds.

Exam trap

The trap here is confusing a 'typical' or 'recommended' TTL with the enforced minimum — candidates often pick 30 seconds because it sounds like a sensible default, but Consul's hard floor is 10 seconds.

How to eliminate wrong answers

Option B is wrong because 30 seconds is a valid TTL but not the minimum — Consul accepts values well below 30 seconds down to the 10-second floor. Option C is wrong because 5 seconds is below the enforced minimum and would be rejected by the Consul agent. Option D is wrong because 1 second is far below the minimum and would generate unsustainable heartbeat load, so Consul refuses it.

30
MCQmedium

You are designing a distributed leader election system using Consul. A service instance must hold a lock on the KV key 'service/leader' to become the leader. You need to ensure that if the instance crashes or loses network connectivity, the lock is automatically released so another instance can acquire it. Which Consul feature should you use to achieve this?

A.Consul sessions with a TTL and the acquire parameter on a KV PUT request
B.Consul watches on the KV key with a script that releases the lock
C.Consul KV key with a long TTL and manual cleanup by an operator
D.Consul prepared queries with failover to another datacenter
AnswerA

Consul sessions provide a mechanism for liveness checking. When you create a session with a TTL and use the acquire parameter on a KV PUT, the key is locked to that session. If the session expires due to missed TTL heartbeats, Consul automatically releases the lock, allowing another instance to acquire it. This is the standard way to implement leader election.

Why this answer

Sessions are the correct mechanism for distributed locks in Consul. By creating a session with a TTL and using the acquire parameter when writing to a KV key, the key becomes locked to that session. If the session expires because the instance fails to renew it, Consul releases the lock, enabling another instance to acquire it.

This pattern is fundamental for leader election.

Exam trap

The trap here is confusing Consul watches with sessions, thinking that a watch can automatically release a lock, but watches only notify and do not manage lock ownership.

31
MCQeasy

A developer has stored the database connection string under the Consul KV path `config/db/primary`. A configuration management script needs to fetch this value as raw text so it can be exported directly into an environment variable. Which Consul CLI command retrieves only the value of that key?

A.consul kv get -detailed config/db/primary
B.consul kv get config/db/primary
C.consul kv export config/db/primary
D.consul kv get -raw config/db/primary
AnswerD

The -raw flag prints the value exactly as stored, with no key name, no metadata, and no JSON wrapper. That makes it the correct choice when a script must capture the value verbatim, for example with command substitution into an environment variable.

Why this answer

The -raw flag suppresses the key name and all metadata, emitting only the stored bytes of the value. When a script needs to assign a KV value directly to a shell variable, any extra formatting breaks the assignment, so the raw form is required. The other commands either add metadata or wrap the value in JSON.

Exam trap

The trap here is assuming that a plain get already returns only the value, when it actually prefixes the key name and may include formatting that breaks direct variable assignment.

32
MCQhard

You need to ensure that a read operation from the KV store is strongly consistent. Which consistency mode should you specify?

A.default
B.consistent
C.quorum
D.stale
AnswerB

Consistent forces a leader check for strong consistency.

Why this answer

The 'consistent' mode forces the Consul server handling the request to forward it to the leader, which then verifies it still holds leadership via a quorum of followers before serving the read. This guarantees linearizable (strongly consistent) reads, ensuring you never see stale data. In contrast, 'default' and 'stale' allow reads from any server and may return outdated values, while 'quorum' is not a valid consistency mode for KV reads.

Exam trap

Consul 1.15 often tests the misconception that 'quorum' is a valid consistency mode, when in fact it is not; candidates must remember the three valid modes: default, consistent, and stale.

How to eliminate wrong answers

Option A is wrong because 'default' uses the same consistency as 'stale' for most reads, permitting any server to respond and potentially returning stale data. Option C is wrong because 'quorum' is not a supported consistency mode for Consul KV reads; the valid modes are 'default', 'consistent', and 'stale'. Option D is wrong because 'stale' explicitly allows reads from any server without leader verification, sacrificing strong consistency for lower latency and higher availability.

33
MCQmedium

You are deploying a service that must store a critical configuration value in Consul KV. The value must only be visible to services with a token that has read access to that specific key. You also need to ensure that any write to the key can only be performed by a token with write access. Which Consul feature should you use?

A.Consul namespaces with a default policy that allows all operations.
B.Consul ACLs with a policy that restricts access to the KV path.
C.Consul KV key-level encryption using the gossip encryption key.
D.Consul intentions that define which services can communicate with the KV store.
AnswerB

ACLs with a policy specifying rules for the KV path allow fine-grained control over read and write access. By attaching a token with that policy, you restrict who can read or write the key. This directly satisfies the requirement that only authorized tokens can access the key.

Why this answer

The requirement is to restrict read and write access to a specific KV key based on tokens. Consul ACLs with policies that define rules for the KV path are the correct mechanism. They allow you to specify exact permissions for tokens, ensuring that only authorized clients can read or write the key.

Other options do not provide this level of access control.

Exam trap

The trap here is confusing encryption or network segmentation with authorization; ACLs are the only way to enforce token-based read/write permissions on KV paths.

34
Multi-Selecthard

Which TWO of the following are true regarding Consul KV watches?

Select 2 answers
A.Watches can only monitor keys that exist
B.Watches use blocking queries internally
C.Watches automatically restart after a script failure
D.Watches can be defined in agent configuration files
E.Watches are only available in the Enterprise edition
AnswersB, D

Consul KV watches rely on blocking queries, where the client sends a request with an index and the server holds it open until data changes or the wait timeout expires. This satisfies the stem's requirement for a true statement about watch internals, avoiding polling overhead through long-poll semantics.

Why this answer

Option B is correct because Consul watches are implemented on top of blocking queries: the watch issues a request with an index and the Consul server holds the connection open until the data changes or the wait time expires, then returns a new index. Option D is correct because watches can be declared in the agent's configuration files (a `watches` block in HCL/JSON) so the agent starts them automatically, in addition to being startable via the `consul watch` CLI command. Option A is wrong because a watch can target a key that does not yet exist and will fire when it is created.

Option C is wrong because Consul does not automatically restart a watch handler script that fails; the handler is simply invoked on each change. Option E is wrong because watches are available in the open-source edition, not only Consul Enterprise.

Exam trap

Consul 1.15 often tests the distinction between watches and blocking queries — candidates forget that watches are built on blocking queries and may incorrectly assume watches require the key to pre-exist or that failed handlers auto-restart.

35
MCQmedium

You are using a Consul Watch to monitor KV changes. What does the 'handler' field specify?

A.The path to the executable to trigger.
B.The address of the Consul server.
C.The filter criteria for the watch.
D.The KV key to watch.
AnswerA

The handler field names the external executable Consul invokes when watched KV data changes, satisfying the requirement to trigger a program on updates. Consul runs this process directly, passing change details via environment variables and stdin, rather than performing any in-process callback or HTTP notification.

Why this answer

In a Consul watch configuration, the `handler` field specifies the path to an executable that Consul invokes when the watched data changes. Consul passes the watch results as JSON on stdin to the handler, and the handler can act on the change (e.g., reload a service, update a config file). It is not a filter, server address, or key path.

Exam trap

The trap is confusing the `handler` (the executable to run) with the watch's `data` fields (what to watch) — candidates often pick the key or filter option because they misread what `handler` controls.

How to eliminate wrong answers

Option B is wrong because the Consul server address is configured via the `-http-addr` flag or `CONSUL_HTTP_ADDR`, not the `handler` field. Option C is wrong because filter criteria are expressed in the watch's `data` block (e.g., `key`, `prefix`, `name`), not in `handler`. Option D is wrong because the KV key to watch is specified in the watch's `data` section (e.g., `key = "foo/bar"`), while `handler` is the executable to run.

36
MCQhard

An operator wants to create a distributed lock using the Consul KV store and sessions. They create a session with `consul session create` and obtain a session ID. They then attempt to acquire a lock on the key `locks/primary` by running `consul kv put -acquire locks/primary leader1`. The command fails with an error indicating the lock is already held. Which of the following best explains why the lock acquisition failed?

A.The operator did not specify a value for the key, and Consul requires a non-empty value to acquire a lock.
B.The key `locks/primary` already has an associated session that holds the lock, and the session is still active.
C.The session ID used for the `-acquire` operation was not created with the `-behavior=release` flag, so it cannot acquire locks.
D.The key `locks/primary` does not exist yet, and Consul requires the key to be created before acquiring a lock.
AnswerB

In Consul, a lock is acquired by associating a session with a key. If the key already has a `Session` field set to an active session, the lock is held. The `-acquire` flag will fail if the lock is already held by a different active session. This is the most likely cause of the error, as it directly reflects the lock semantics.

Why this answer

Lock acquisition in Consul KV uses sessions. When a key has an active session associated with it, that session holds the lock. A new `-acquire` attempt with a different session will fail because the lock is already held.

The other options describe incorrect requirements or behaviors that do not match Consul's lock semantics.

Exam trap

The trap here is assuming that a lock can be acquired on a key that already has an active session, or misattributing the failure to session behavior flags or key existence.

37
MCQmedium

When a session is associated with a lock, what happens to the lock if the session is deleted?

A.The lock remains held by the server.
B.The lock is held until the key is deleted.
C.The lock is released.
D.The lock transfers to a new session.
AnswerC

Deleting a session immediately releases its associated lock, because Consul ties lock lifetime to the session's health rather than to the client holding it. This satisfies the stem's constraint: once the session no longer exists, the lock cannot persist, so waiting contenders acquire it without manual intervention.

Why this answer

Consul locks are bound to the session that acquired them. When a session is deleted — whether explicitly via the session destroy API or implicitly through TTL expiry — Consul automatically releases every lock and KV entry associated with that session. This is the core safety property that makes session-based locking reliable for leader election.

Exam trap

The trap is conflating session deletion with key deletion — candidates may think the lock persists until the KV key is removed, but Consul releases locks on session destruction regardless of whether the key still exists.

How to eliminate wrong answers

Option A is wrong because locks are not held by the server independently of a session; the session is the ownership token, and destroying it releases the lock. Option B is wrong because the lock is not tied to the key's existence — deleting the session releases the lock even though the key remains in the KV store. Option D is wrong because Consul does not transfer locks between sessions; a new session must explicitly acquire the lock via a fresh PUT with the acquire parameter, and lock-delay may block that acquisition temporarily.

38
Multi-Selectmedium

Which TWO of the following are true about the 'cas' parameter in KV writes?

Select 2 answers
A.It is only available in the CLI
B.It only works for new keys
C.It stands for Check-And-Set
D.It is mandatory for all writes
E.It requires a valid ModifyIndex
AnswersC, E

The `cas` parameter stands for Check-And-Set, providing optimistic concurrency control for KV writes. Supplying a `cas` value makes the write conditional: Consul compares it against the key's current `ModifyIndex` and only commits if they match, returning an error otherwise. This satisfies the scenario's requirement to prevent overwriting concurrent updates.

Why this answer

Option C is correct because 'cas' stands for Check-And-Set, the Consul KV write flag that makes a write conditional on the key's current ModifyIndex. Option E is correct because using cas requires supplying a valid ModifyIndex value: the write succeeds only if it matches the key's current index, otherwise Consul returns an error (e.g., HTTP 409). The other options are wrong: cas is available through the HTTP API and UI as well as the CLI, it works for existing keys (not only new ones), and it is optional rather than mandatory for all writes.

Exam trap

Consul 1.15 often tests the misconception that 'cas' is only for new keys or that it's mandatory, confusing candidates about its conditional nature and availability across interfaces.

39
MCQeasy

A system administrator needs to delete a single key named `temp/config` from the Consul KV store. They want to ensure that only that key is removed and no other keys are affected. Which command should they use?

A.consul kv delete temp/config
B.consul kv delete -recurse temp/config
C.consul kv export temp/config | consul kv delete -
D.consul kv put temp/config ""
AnswerA

The `consul kv delete` command removes the specified key. When given a full key path like `temp/config`, it deletes only that key. It does not affect other keys. This is the precise command for deleting a single key, matching the administrator's requirement.

Why this answer

The `consul kv delete` command with a specific key path deletes only that key. The `-recurse` flag would delete the key and all subkeys, which is not desired. Writing an empty value does not delete the key.

The pipeline approach is invalid. Therefore, the simple delete command is correct.

Exam trap

The trap here is confusing deletion with writing an empty value, or using the `-recurse` flag when only a single key should be removed.

40
MCQmedium

You are using Consul KV to coordinate a distributed job scheduler. A worker acquires a lock on a key to ensure only one worker runs a job at a time. The lock is tied to a session. The worker crashes and the session expires after its TTL. What happens to the lock on the key?

A.The key is deleted and the lock is released.
B.The lock is automatically released and the key's LockIndex is incremented.
C.The lock is automatically released and the key's value is deleted.
D.The lock remains held until a Consul operator manually releases it.
AnswerB

When a session that holds a lock expires, Consul releases the lock by clearing the Session field and incrementing the LockIndex. This allows other sessions to acquire the lock. The key and its value remain unchanged. This behavior ensures that locks do not become stuck after a session expires.

Why this answer

When a session expires, Consul automatically releases any locks held by that session. The lock release is indicated by clearing the Session field on the key and incrementing the LockIndex. The key and its value are not deleted.

This allows other workers to acquire the lock and continue operation. Manual intervention is not required.

Exam trap

The trap here is assuming that lock release deletes the key; in reality, the key remains and only the lock metadata changes.

41
MCQmedium

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?

A.consistency
B.wait
C.index
D.timeout
AnswerC

Supplying the index parameter tells Consul to hold the blocking query open until the KV store's modify index exceeds that value, returning only on change or timeout. This satisfies the stem's requirement to watch for updates based on the last observed index, avoiding repeated polling.

Why this answer

To perform a blocking query on a KV key, you must provide the 'index' parameter, which specifies the last observed ModifyIndex. Consul will hold the request until the key's index exceeds this value or the wait time expires.

Exam trap

Consul 1.15 often tests blocking query parameters; candidates may confuse 'wait' with 'index', but 'index' is mandatory to enable blocking behavior.

How to eliminate wrong answers

Option A is wrong because 'consistency' is used to specify consistency modes (e.g., 'stale', 'consistent') but does not enable blocking. Option B is wrong because 'wait' specifies the maximum duration to wait, but without 'index', the query is not blocking. Option D is wrong because 'timeout' is not a standard parameter for blocking queries; 'wait' is used instead.

42
MCQeasy

You need to store a value in Consul KV that will be read by a service. The value should be retrievable by a simple HTTP GET request to the Consul API. Which HTTP endpoint should you use to read the value of a key named 'app/config/db_host'?

A.GET /v1/kv/read/app/config/db_host
B.GET /v1/store/app/config/db_host
C.GET /v1/kv/app/config/db_host?raw
D.GET /v1/kv/app/config/db_host
AnswerD

The correct endpoint to read a KV value is GET /v1/kv/ followed by the key path. For the key 'app/config/db_host', the URL is /v1/kv/app/config/db_host. This returns a JSON array containing the key's value, flags, and metadata. It is the standard way to retrieve a single key.

Why this answer

The Consul KV API uses the /v1/kv/ prefix for all key operations. To read a key, you perform a GET request to /v1/kv/<key>. This returns a JSON response containing the value and metadata.

Other paths like /v1/store or /v1/kv/read are not valid. The ?raw parameter is optional and returns the value directly, but the standard endpoint is without it.

Exam trap

The trap here is adding unnecessary path segments or using a different prefix; the KV API is consistently under /v1/kv/.

43
MCQhard

When using Consul KV for distributed locking, why is it recommended to use a session?

A.It allows for TTL-based automatic lock release.
B.It encrypts the lock data.
C.It allows for multiple lock holders.
D.It speeds up read operations.
AnswerA

A Consul session binds the lock key to a TTL-backed session, so if the holder fails or stops renewing, the session expires and the lock is released automatically. This prevents deadlocks without manual intervention, satisfying the need for automatic lock release.

Why this answer

Sessions in Consul provide a mechanism for TTL-based automatic lock release. When a lock is acquired using a session, the session must be periodically renewed; if the client fails to renew before the TTL expires, Consul automatically invalidates the session and releases any locks held by it, preventing deadlocks from crashed or partitioned clients.

Exam trap

The trap is conflating sessions with security features like encryption; candidates may assume 'session' implies confidentiality, when in fact its purpose is liveness detection and automatic lock cleanup.

How to eliminate wrong answers

Option B is wrong because sessions do not encrypt lock data; encryption is handled separately via TLS and gossip encryption, and the KV values themselves are not encrypted by Consul. Option C is wrong because a session-based lock is designed for mutual exclusion — only one holder at a time — not multiple concurrent holders. Option D is wrong because sessions add coordination overhead and do not accelerate read operations; reads are served from the KV store regardless of session state.

44
Multi-Selecthard

An engineer is designing a service that must coordinate access to a shared resource using Consul KV sessions and needs to understand the guarantees the lock provides. Which TWO statements accurately describe how Consul's KV locking with sessions behaves? (Choose two.)

Select 2 answers
A.Session TTL renewal must be performed through the `/v1/kv` endpoint rather than the session endpoint.
B.A lock is acquired by writing a key with the `acquire` parameter and the session ID, and succeeds only if no other valid session currently holds it.
C.A lock key can be held simultaneously by multiple sessions as long as each session renews within its TTL.
D.Releasing a lock requires calling a dedicated `consul kv unlock` subcommand that is separate from the put operation.
E.If the session holding a lock expires or is invalidated, the lock key is automatically released so another session can acquire it.
AnswersB, E

Lock acquisition uses the `acquire` operation, passing the candidate's session ID. Consul checks whether the key is currently held by a live session; if not, the write succeeds and records the session ID in the key's Session field. If another valid session holds it, the acquire fails. This is the fundamental mechanism that makes Consul KV locks mutually exclusive.

Why this answer

Consul locks are acquired with the `acquire` operation carrying a session ID, and they are released automatically when that session expires or is invalidated. Mutual exclusion is guaranteed because only one valid session can hold a given key. Release is performed through the same key-write path with the `release` operation, and session renewal happens at the session endpoint, not the KV endpoint.

Exam trap

The trap here is conflating session renewal with KV lock operations, when renewal occurs through the session endpoint and locks are managed through acquire and release on the key itself.

45
Multi-Selectmedium

A team is using the Consul KV store to store application configuration. They want to implement a watch that runs a script whenever the value of the key `config/app` changes. Which two of the following statements are true regarding Consul KV watches? (Choose two.)

Select 2 answers
A.Watches are only available in Consul Enterprise and not in the open-source version.
B.Watches can only be configured via the Consul HTTP API and not through the CLI or configuration files.
C.A watch of type `key` blocks until the value of the specified key changes, then invokes the handler.
D.A watch of type `keyprefix` monitors all keys under a prefix and triggers when any key in that prefix changes.
E.A watch of type `key` will automatically create the key if it does not exist.
AnswersC, D

Consul watches support a `key` type that monitors a single key. The watch uses blocking queries to wait for changes. When the key's value or metadata changes, the watch returns the new data and invokes the configured handler. This is the intended use for reacting to changes in a specific key.

Why this answer

Watches in Consul allow monitoring of KV changes. The `key` type watches a single key and blocks until it changes. The `keyprefix` type watches a prefix and triggers on any change within it.

These are both standard watch types. Watches can be configured via CLI, API, or agent configuration, and they do not create keys. They are available in all Consul versions.

Exam trap

The trap here is assuming that watches can create keys or are limited to Enterprise, or that they are configured only via one method.

46
MCQhard

If a KV operation returns a 403 Forbidden status, what is the most common cause?

A.The ACL token lacks sufficient permissions.
B.The server is down.
C.The data is too large.
D.The key does not exist.
AnswerA

A 403 Forbidden from Consul's KV store signals authorisation failure, not authentication failure. The ACL token presented is valid but its policy grants no matching `key:read` or `key:write` capability for that path. Consul evaluates token policies against the requested KV prefix and denies access when no rule permits it.

Why this answer

A 403 Forbidden response from Consul's HTTP API indicates the request was authenticated but the associated ACL token does not have the required policy permissions for the target resource. Consul returns 403 specifically when an ACL is enforced and the token lacks the necessary 'read', 'write', or 'list' capability on the KV prefix being accessed. This is distinct from 401 (missing/invalid token) and 404 (key not found).

Exam trap

Consul 1.15 often tests the distinction between HTTP status codes — candidates confuse 403 (permission denied) with 401 (unauthenticated) or 404 (resource missing), so they pick 'key does not exist' when the real signal is an ACL denial.

How to eliminate wrong answers

Option B is wrong because a down server produces a connection refused/timeout error, not an HTTP 403 response — the API would not be reachable to return a status code. Option C is wrong because oversized values return 413 Request Entity Too Large (Consul caps KV values at 512 KB), not 403. Option D is wrong because a missing key returns 404 Not Found (or an empty result for a prefix list), not 403 Forbidden.

47
MCQhard

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?

A.Immediately.
B.60 seconds.
C.The lock is never released until manually deleted.
D.15 seconds.
AnswerD

The session TTL defines the duration after which an un-renewed session is invalidated, releasing associated locks.

Why this answer

Consul sessions are invalidated when their TTL expires without a renewal. With a 15-second TTL, if the application crashes and stops calling session renew, the session becomes invalid after 15 seconds, and any locks or KV entries tied to that session are released at that point. The lock release is therefore bounded by the session TTL, not by any manual intervention.

Exam trap

The trap is assuming Consul detects failures instantly or that lock release requires manual action — candidates must remember that session-based locks are released only after the configured TTL elapses, and that lock-delay can extend that window further.

How to eliminate wrong answers

Option A is wrong because Consul cannot detect a crash instantaneously — it relies on TTL expiry or explicit session destruction, so release is not immediate. Option B is wrong because 60 seconds is not derived from any Consul default; the session TTL is explicitly configured as 15 seconds, and Consul honors that value (subject to the 10x TTL multiplier for lock-delay, which is a separate concept). Option C is wrong because sessions are designed precisely to auto-release locks on failure; manual deletion is only required if the session is still being renewed or if lock-delay is configured to hold the lock.

48
MCQhard

If a Consul agent is configured with 'disable_remote_exec = true', how does this affect the KV store?

A.It forces all KV reads to be consistent.
B.It prevents all KV writes.
C.It disables KV watches.
D.It has no effect on the KV store.
AnswerD

disable_remote_exec only blocks Consul's remote exec functionality, preventing command execution on agents. The KV store is a separate subsystem accessed via its own HTTP API, so this setting leaves key-value operations entirely unaffected, matching the option's no-effect claim.

Why this answer

'disable_remote_exec' controls whether Consul's remote execution feature (the 'consul exec' command) is allowed on the agent. It has no relationship to the KV store — KV reads, writes, watches, and consistency modes are governed by separate ACL and query parameters. Setting this flag simply blocks remote command execution for security hardening.

Exam trap

Consul 1.15 often tests whether candidates conflate security-hardening flags with data-plane behaviour — the trap is assuming any agent-level restriction affects the KV store, when in fact disable_remote_exec only gates the exec subsystem.

How to eliminate wrong answers

Option A is wrong because KV read consistency is controlled by the 'consistent', 'stale', or 'default' query parameters and the '?consistent' flag, not by remote exec settings. Option B is wrong because KV writes are gated by ACL policies and Raft leadership, not by disable_remote_exec. Option C is wrong because KV watches are implemented via blocking queries on the KV endpoint and are unaffected by remote exec configuration.

49
MCQmedium

You are deploying a service that requires distributed locking with automatic release if the service instance fails. You have created a session named 'lock-session' and acquired a lock on the KV key 'locks/db'. After a few minutes, the lock is unexpectedly released even though the service instance is still running. Which action should you take to diagnose the most likely cause?

A.Inspect the KV key's metadata to see if it was modified externally.
B.Check the Consul server logs for errors related to the session.
C.Restart the Consul agent on the node where the service is running.
D.Verify that the service is sending session renewals within the TTL period.
AnswerD

Consul sessions are invalidated if not renewed within their TTL. If the service fails to renew the session, the lock is released automatically. This is the most likely cause when the service is still running but not properly renewing. Checking renewal activity directly addresses the root cause and is the correct diagnostic step.

Why this answer

Consul sessions have a TTL and must be periodically renewed by the client. If the service fails to renew within the TTL, the session is invalidated and any locks held by that session are released. In this scenario, the service is still running but likely not renewing the session, causing the lock to be released.

Verifying renewal activity is the correct diagnostic step.

Exam trap

The trap here is assuming that the lock is released due to external interference or server issues, rather than the session TTL expiring because of missed renewals.

50
MCQmedium

An operator writes a feature flag to `app/features/new-ui` using `consul kv put app/features/new-ui true`. Later, a health-check script reads that key and receives an error instead of the value. The operator confirms the key exists with `consul kv get app/features/new-ui`. Which command should the operator run to inspect the metadata that would reveal a problem such as a missing or expired session on the key?

A.consul kv put app/features/new-ui -flags=42
B.consul catalog nodes -service=app
C.consul kv get -recurse app/features/
D.consul kv get -detailed app/features/new-ui
AnswerD

The -detailed flag adds CreateIndex, ModifyIndex, LockIndex, Flags, and Session to the output. Inspecting the Session field shows whether a session is attached to the key, and the absence or expiry of that session explains why a lock-holding reader may fail while a plain read succeeds.

Why this answer

Metadata such as the attached session and lock index is only exposed when the detailed view is requested. A key can be readable while still being held by a session, and a health script that attempts to acquire the lock will fail in that case. Requesting the detailed output surfaces the session identifier needed to investigate further.

Exam trap

The trap here is treating a successful plain read as proof the key is healthy, when the real fault lies in session metadata that only the detailed view exposes.

51
MCQmedium

You need to retrieve the session information for a specific session ID. Which endpoint should you query?

A./v1/session/read/:id
B./v1/session/info/:id
C./v1/kv/session/:id
D./v1/session/get/:id
AnswerB

The /v1/session/info/:id endpoint returns details for the session matching the supplied ID, satisfying the requirement to retrieve one specific session's information. Other session endpoints create, destroy or list sessions, so they cannot target an individual identifier.

Why this answer

The Consul HTTP API exposes session information through the /v1/session/info/:id endpoint, which returns the full session object (ID, node, checks, behavior, TTL, lock-delay) for the specified UUID. This is the documented read endpoint for a single session, distinct from /v1/session/list (all sessions) and /v1/session/node/:node (sessions on a node).

Exam trap

Consul 1.15 often tests whether candidates know the exact HTTP API verb/path for session operations — the trap is confusing /v1/session/info/:id with plausible-sounding but nonexistent paths like /read or /get.

How to eliminate wrong answers

Option A is wrong because /v1/session/read/:id is not a valid Consul API path — there is no 'read' action under the session resource. Option C is wrong because /v1/kv/session/:id does not exist; the KV store has no session sub-resource, and sessions are managed under /v1/session. Option D is wrong because /v1/session/get/:id is not a Consul endpoint — 'get' is not used as an action verb in the session API.

52
MCQeasy

An operator runs `consul kv put config/app/timeout 30s` and then `consul kv get config/app/timeout`. The second command prints only `30s` with no metadata. The operator wants to see the key's `CreateIndex`, `ModifyIndex`, and `Flags` from the command line without writing code against the HTTP API. Which command should be used?

A.`consul catalog nodes -service=config/app/timeout`
B.`consul kv export config/app/timeout`
C.`consul kv get -detailed config/app/timeout`
D.`consul kv get -recurse config/app/timeout`
AnswerC

The `-detailed` flag on `consul kv get` prints the key's metadata fields, including `CreateIndex`, `ModifyIndex`, `LockIndex`, `Flags`, and `Session`, in addition to the value. It is the intended CLI way to inspect KV entry metadata without issuing raw HTTP requests, which is precisely what the operator needs here.

Why this answer

The CLI exposes KV metadata through the `-detailed` flag on `consul kv get`, which prints `CreateIndex`, `ModifyIndex`, `LockIndex`, `Flags`, `Session`, and the value. Plain `get` and `-recurse` show only names and values, while `export` emits a JSON tree for backup. To see index and flag fields from the shell, `-detailed` is the correct choice.

Exam trap

The trap here is assuming `-recurse` or `export` reveals metadata, when only the `-detailed` flag on `consul kv get` prints index, lock, flag, and session fields.

53
MCQmedium

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?

A.raw=true
B.list=true
C.summarize=true
D.keys=true
AnswerD

Appending `keys=true` to a KV list request returns only key names, omitting values and metadata from the response body. This directly satisfies the stem's payload-reduction constraint, since the default list operation includes values for every key under the prefix, inflating the response unnecessarily.

Why this answer

The `keys=true` query parameter on the Consul KV list endpoint instructs the API to return only the key names under the given prefix, omitting the associated values. This dramatically reduces the response payload size when you only need to enumerate keys rather than retrieve their contents. It is the documented way to perform a lightweight listing operation against a KV prefix.

Exam trap

The trap here is confusing the `keys` parameter with `raw` or inventing non-existent parameters like `list` or `summarize`; candidates who have only skimmed the KV API docs may pick `raw=true` thinking it means 'raw list' rather than 'raw single value'.

How to eliminate wrong answers

Option A is wrong because `raw=true` does the opposite of reducing payload — it returns the raw, un-decoded value of a single key, bypassing the standard JSON envelope, and is only valid on a single-key read, not a list operation. Option B is wrong because `list=true` is not a valid Consul KV API parameter; listing is achieved by appending `?recurse` or using the `/v1/kv/<prefix>?keys` endpoint, so this option invents a parameter that does not exist. Option C is wrong because `summarize=true` is not a Consul KV API parameter — Consul does not offer a summarize flag on KV reads, so this is a fabricated option designed to sound plausible.

54
MCQeasy

Which Consul feature allows you to observe the KV store for changes and run a command in response?

A.KV Hooks
B.Consul Watches
C.Consul Events
D.Consul Connect
AnswerB

Consul Watches monitor a specified KV prefix or key for changes and invoke a handler, such as an executable script, when an update occurs. This satisfies the requirement to observe the KV store and run a command in response.

Why this answer

Consul Watches are a mechanism that allows you to monitor specific Consul data (such as KV pairs, health checks, or service listings) for changes and trigger an external handler (e.g., a script or HTTP endpoint) when a change occurs. The watch polls the Consul API at a specified interval and invokes the handler with the updated data. This is the intended feature for reacting to KV store modifications.

Exam trap

The trap here is confusing Consul Events with Watches; candidates often think Events are used for monitoring KV changes, but Events are for custom broadcasts, while Watches are for observing data changes and triggering actions.

How to eliminate wrong answers

Option A is wrong because 'KV Hooks' is not a Consul feature; it is a fabricated term. Option C is wrong because Consul Events are used for broadcasting custom user events via the event API, not for observing KV changes and running commands. Option D is wrong because Consul Connect provides service-to-service mTLS encryption and authorization, not KV change monitoring.

55
Multi-Selecteasy

Which TWO of the following are common use cases for the Consul KV store?

Select 2 answers
A.Traffic routing
B.Distributed locking
C.Service discovery
D.Running custom scripts
E.Distributed configuration management
AnswersB, E

Consul's KV store supports acquire and release operations backed by session-based consensus, letting clients hold a lock key exclusively. This satisfies the distributed locking use case: multiple service instances coordinate leader election or serialised access without an external coordinator.

Why this answer

Option B (Distributed locking) is correct because Consul KV supports acquiring and releasing locks via sessions, using the KV store's compare-and-swap semantics combined with session invalidation to implement distributed locking and leader election. Option E (Distributed configuration management) is correct because Consul KV is commonly used to store application configuration key/value pairs that services read at runtime, with Consul's blocking queries and watches enabling dynamic config updates. Option A (Traffic routing) is not a KV use case; traffic routing is handled by Consul service mesh features such as intentions, service resolvers, and Envoy sidecar proxies.

Option C (Service discovery) is provided by Consul's catalog and DNS/HTTP service registration APIs, not the KV store. Option D (Running custom scripts) is not a Consul KV function; Consul executes scripts only via health checks or watches that trigger external handlers, not as a KV capability.

Exam trap

The trap is confusing KV with service discovery or traffic routing; candidates see 'Consul' and pick service discovery, but the question specifically asks about the KV store's use cases, which are locking and configuration.

56
MCQhard

A microservice uses a Consul session with a 30-second TTL and holds a lock on `locks/leader` via `acquire`. The service process is alive and healthy but its network link to the Consul servers is severed for several minutes. When connectivity is restored, the service finds it no longer owns the lock. Which behavior explains this outcome?

A.The lock was released because Consul applies a fixed maximum lock hold time of 15 seconds regardless of session TTL settings.
B.The session TTL expired because the service failed to renew it within the TTL window, so Consul invalidated the session and released its locks.
C.Consul invalidated the session because the node's health check for the service was marked critical during the outage.
D.The lock moved to another session immediately after the partition began because Consul rebalances locks among active sessions automatically.
AnswerB

Sessions are kept alive only by timely renewal; if the client cannot reach the servers to renew within the TTL, the session expires and Consul deletes it, which releases every lock and invalidates every key held by that session. The severed link prevented renewal, so the lock was freed exactly as designed.

Why this answer

Session-based locks in Consul are leases: the client must renew the session before its TTL elapses, and failure to renew causes the session to expire, which deletes the session and releases all locks and keys it held. A network partition that blocks renewal therefore forfeits the lock, which is the intended safety behavior preventing a partitioned leader from retaining ownership indefinitely.

Exam trap

The trap here is blaming health-check invalidation or an automatic lock rebalance, when the default session behavior releases locks solely because the unrenewed TTL expired.

57
Multi-Selecthard

You are designing a configuration system where multiple instances of a service must coordinate to elect a single leader using Consul KV. Which two statements accurately describe how to implement leader election with sessions? (Choose two.)

Select 2 answers
A.Each instance should create a session with a unique name and then attempt to acquire the same KV key using PUT /v1/kv/service/leader?acquire=<session_id>.
B.To release leadership, the leader can simply delete the KV key, which automatically invalidates its session and allows another instance to acquire the lock.
C.The leader should periodically renew its session using PUT /v1/session/renew/<session_id> to maintain the lock, and if renewal fails, it should assume leadership is lost.
D.All instances should use the same session ID to ensure they can all attempt to acquire the lock simultaneously, and the first one to call acquire becomes the leader.
E.The KV key used for leader election must have a TTL set via the ?ttl= query parameter, so that it expires automatically if the leader fails.
AnswersA, C

This is the correct pattern for leader election. Each candidate creates a session and attempts to acquire a shared key. Only one session can hold the lock at a time. The successful acquirer becomes the leader, and others receive a false response and should retry or wait.

Why this answer

Leader election with Consul KV relies on sessions and the acquire operation. Each candidate creates a unique session and attempts to acquire a shared key. The holder must renew its session to keep the lock; if renewal fails, the session expires and the lock is released.

Deleting the key or sharing sessions does not provide correct coordination, and KV entries do not support TTLs.

Exam trap

The trap here is assuming that deleting the KV key or setting a TTL on the key can replace session renewal, when in fact only session invalidation releases the lock.

Ready to test yourself?

Try a timed practice session using only Key Value Store questions.