Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Specify multi-tier state persistence components that address session state, shared team state, and long-term semantic memory with lifecycle and tenant-isolation policies

A worked example

Complete the statement

An investment firm runs a shared pool of research agents that serves hundreds of client tenants. Several agents contribute to the same research task document, each writing to its own section. You must specify the store for this shared task state.

Requirements:

  • Task state must be shared by all agents and must survive restarts of any agent process.
  • Agents often query all pending tasks for one client. A trusted data-access layer obtains the client ID from validated tenant context. Each query must use request-level scope that confines results to that client's documents even if its SQL filter is faulty.
  • Conflicting writes are rare. Agents must never wait for another agent's lock before reading or writing task state.
  • A write based on stale data must be rejected, not silently overwrite another agent's contribution.

Complete the design for the shared task state.

Store shared task state in , scope client queries by using , and apply updates by using .

  • Blank 1: Azure Cosmos DB for NoSQL (correct answer)

    Azure Cosmos DB supports durable shared documents, partition-scoped queries, and ETag-based conditional updates. Azure Managed Redis supports shared caching but lacks the native partition-key query scope required here. In-process agent memory is lost on restart and is not shared between agent processes.

  • Blank 2: a /tenantId partition key with each query explicitly scoped to the client's partition (correct answer)

    Using /tenantId and supplying the validated client ID as the query's partition-key request option confines that query to the client's logical partition independently of its SQL filter. Scoping a /taskId partition to one task cannot return all pending tasks for the client. Tenant-prefixed IDs alone do not restrict a query that spans partitions.

  • Blank 3: ETag-based optimistic concurrency (correct answer)

    ETag-based optimistic concurrency uses conditional writes to reject an update when the document has changed since it was read, without acquiring distributed locks. A SETNX distributed lock makes competing agents wait and serializes access. Upserts without a version check can silently overwrite another agent's contribution.

Why

Azure Cosmos DB provides durable task documents that multiple agents can share across process restarts. With /tenantId as the partition key, the trusted data-access layer must explicitly supply the validated client ID in each query's partition-key request option, so faulty SQL filters cannot broaden that query beyond the client's partition. A task-scoped partition cannot return all of a client's tasks, and document ID prefixes alone do not constrain cross-partition queries. ETag-based conditional updates reject stale writes without distributed locks, fitting the requirement for parallel access when conflicts are rare.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free