---
title: Stateful Data, AI & Messaging Infrastructure
summary: Technical reference for Azure-managed databases, caches, storage, Durable Task Scheduler, Microsoft Foundry, and external dependencies.
owners:
  - platform-engineering-team
badges:
  - content: Infrastructure Reference
    backgroundColor: blue
    textColor: blue
---

Each BookWorm bounded context owns its authoritative persistence, isolated behind service APIs and authenticated via Microsoft Entra ID RBAC. This reference documents the Azure-managed data and AI stores alongside external messaging, vector search, and email dependencies.

## Data, AI, and Messaging Topology

<MermaidFileLoader file="mermaids/003-data-ai-and-messaging-resources-diagram-1.mmd" />

## Component & Responsibility

| Component                      | Role                                            | Protocol / Interface                        | Persistence / State                                                                                                   | Notes                                                                                                                                     |
| :----------------------------- | :---------------------------------------------- | :------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------- |
| **PostgreSQL Flexible Server** | Relational & event-store persistence            | PostgreSQL 16 (Entra ID auth)               | [[container\|catalog-database]], [[container\|order-database]], [[container\|scheduler-database]]                     | Password auth disabled; PgBouncer in Staging/Prod                                                                                         |
| **Azure Managed Redis**        | Distributed cache, basket state & idempotency   | TLS port `10000` (Entra ID auth)            | [[container\|basket-database]], [[container\|catalog-cache]], [[container\|order-cache]], [[container\|rating-cache]] | Used by [[service\|catalog-api]], [[service\|basket-api]], [[service\|order-api]], [[service\|rating-api]], [[service\|notification-api]] |
| **Azure Cosmos DB**            | Customer feedback document store                | EF Core Cosmos (Session consistency)        | [[container\|rating-database]] (partitioned by book ID)                                                               | Owned by [[service\|rating-api]] only                                                                                                     |
| **Azure Storage**              | Blob assets & Azure Functions host state        | HTTPS (TLS 1.2+, Managed Identity)          | [[container\|catalog-blob]], [[container\|chat-session-blob]], Functions host                                         | Public blob access disabled                                                                                                               |
| **Durable Task Scheduler**     | Durable orchestration state & timers            | Managed Identity auth                       | Order workflow task hub                                                                                               | Owned by [[service\|order-orchestration]] only                                                                                            |
| **Microsoft Foundry**          | Managed LLM chat, routing & embedding inference | HTTPS (Cognitive Services User RBAC)        | Stateless inference (`S0` + App Insights)                                                                             | Used by [[service\|catalog-api]], [[service\|catalog-ingestion]], [[service\|chat-api]], [[service\|rating-api]]                          |
| **Kafka Broker**               | Asynchronous event & command transport          | Kafka                                       | Topic logs & dead-letter queues                                                                                       | Wolverine transport with CloudEvents JSON                                                                                                 |
| **Qdrant Cloud**               | Derived semantic vector search index            | gRPC / HTTP                                 | [[container\|catalog-vector]]                                                                                         | Read by [[service\|catalog-api]]; written by [[service\|catalog-ingestion]]                                                               |
| **SMTP Relay**                 | External transactional email delivery           | SMTP port `587` ([[service\|sendgrid-api]]) | Stateless relay                                                                                                       | Used by [[service\|notification-api]]; Mailpit in local run mode                                                                          |

## Configuration & Operational Defaults

### Data Ownership per Service

| Service                          | Primary store                                    | Cache / idempotency               | Messaging                         | Other                                                               |
| :------------------------------- | :----------------------------------------------- | :-------------------------------- | :-------------------------------- | :------------------------------------------------------------------ |
| [[service\|catalog-api]]         | [[container\|catalog-database]]                  | [[container\|catalog-cache]]      | Kafka + PostgreSQL outbox/inbox   | [[container\|catalog-vector]], [[container\|catalog-blob]], Foundry |
| [[service\|catalog-ingestion]]   | [[container\|catalog-database]] (read)           | —                                 | Kafka trigger + PostgreSQL outbox | [[container\|catalog-vector]] (write), Foundry, host storage        |
| [[service\|basket-api]]          | [[container\|basket-database]]                   | [[container\|basket-database]]    | Kafka                             | No SQL database                                                     |
| [[service\|order-api]]           | [[container\|order-database]] (EF Core + Marten) | [[container\|order-cache]]        | Kafka + PostgreSQL outbox/inbox   | —                                                                   |
| [[service\|order-orchestration]] | Durable Task Scheduler                           | —                                 | Kafka                             | Host storage; no PostgreSQL                                         |
| [[service\|rating-api]]          | [[container\|rating-database]]                   | [[container\|rating-cache]]       | Kafka + Cosmos DB persistence     | Foundry; no PostgreSQL                                              |
| [[service\|chat-api]]            | [[container\|chat-session-blob]]                 | —                                 | —                                 | Foundry; no PostgreSQL, Redis, or Kafka                             |
| [[service\|mcp-server]]          | — (stateless)                                    | —                                 | —                                 | —                                                                   |
| [[service\|notification-api]]    | —                                                | Redis (FusionCache + idempotency) | Kafka                             | MailKit + Mjml.Net over SMTP; no PostgreSQL                         |
| [[service\|scheduler-service]]   | [[container\|scheduler-database]]                | —                                 | Kafka + PostgreSQL outbox/inbox   | —                                                                   |

### Kafka Messaging Conventions

- **Transport:** Wolverine with Kafka transport and CloudEvents JSON serialization (propagates W3C trace context, request ID, and user identity).
- **Default topic naming:** `bookworm.{env}.{owner-service}.{topic-name}` (exception: `scheduler.process-vector-batch` is unprefixed).
- **Dead-letter queues:** One native dead-letter queue per service (`bookworm.{env}.{service}.dead-letter-queue`).
- **Retry policy:** Cooldowns of `50ms`, `250ms`, and `1s` with full jitter before routing to the native dead-letter queue.

<AccordionGroup>
	<Accordion title="Azure-Managed Store SKUs by Environment">
		#### PostgreSQL Flexible Server

    	| Property | `Development` | `Staging` | `Production` |
    	| :------- | :------------ | :-------- | :----------- |
    	| SKU / tier | `Standard_B1ms` (Burstable) | `Standard_D2ds_v5` (General Purpose) | `Standard_D4ds_v5` (General Purpose) |
    	| High availability | Disabled | Zone-redundant (zones 1 & 2) | Zone-redundant (zones 1 & 2) |
    	| Backup retention | 7 days | 14 days | 35 days |
    	| Geo-redundant backup | Disabled | Disabled | Enabled |
    	| Storage | 32 GB, auto-grow off | 128 GB, auto-grow on | 256 GB, auto-grow on |
    	| PgBouncer | Disabled | Enabled | Enabled |

    	#### Azure Managed Redis

    	| Property | `Development` | `Staging` | `Production` |
    	| :------- | :------------ | :-------- | :----------- |
    	| SKU | `BalancedB0` | `BalancedB1` | `BalancedB5` |
    	| High availability | Disabled | Enabled | Enabled |

    	#### Azure Cosmos DB

    	| Property | `Development` | `Staging` | `Production` |
    	| :------- | :------------ | :-------- | :----------- |
    	| Capacity mode | Serverless | Serverless | Provisioned throughput |
    	| Local (key) auth | Enabled | Disabled | Disabled |

    	#### Azure Storage (publish mode only)

    	| Property | `Development` | `Staging` | `Production` |
    	| :------- | :------------ | :-------- | :----------- |
    	| SKU | `Standard_LRS` | `Standard_ZRS` | `Standard_GZRS` |
    	| Access tier / TLS | Hot / TLS 1.2+ | Hot / TLS 1.2+ | Hot / TLS 1.2+ |
    </Accordion>
    <Accordion title="Microsoft Foundry Model Deployments">
    	Foundry provisions SKU `S0` with an `Agents` capability host and links Application Insights. All deployments use `GlobalStandard` capacity `1`.

    	| Deployment | Model | Version | Purpose |
    	| :--------- | :---- | :------ | :------ |
    	| `chat` | `model-router` | `2025-11-18` | Chat completions and agent reasoning |
    	| `decision` | `Microsoft-Decision-1` | `1` | Chat workflow routing decisions |
    	| `embedding` | `embed-v-4-0` | `6` | Catalog vector embeddings |
    </Accordion>

</AccordionGroup>

## Guardrails & Constraints

<Admonition type="warning" title="Restrict Network & CORS Policies Before Production">
	Azure Storage Blob CORS currently permits all origins (`*`, 1-hour cache), and Durable Task
	Scheduler declares an open IP allowlist (`0.0.0.0/0`). Restrict both to known gateway and workload
	boundaries before Production; see [[doc|operational/004-security-hardening-checklist]].
</Admonition>

<Admonition type="info" title="PostgreSQL Database Isolation">
	PostgreSQL hosts **only** [[container|catalog-database]], [[container|order-database]], and
	[[container|scheduler-database]]. [[service|order-orchestration]], [[service|notification-api]],
	[[service|basket-api]], [[service|rating-api]], and [[service|chat-api]] must never provision
	relational PostgreSQL databases.
</Admonition>

## Related Documentation

- [[doc|platform/002-compute-and-container-apps]] — Workloads that consume these resources.
- [[doc|platform/004-identity-and-rbac-matrix]] — Role assignments for each resource.
- [[doc|operational/004-security-hardening-checklist]] — Network, backup, and quota hardening.
- [[doc|operational/003-incident-response-and-runbooks]] — Datastore and messaging recovery steps.

<ArchitectureGraph id="catalog-ingestion" type="service" depth="2" maxHeight="28" />
