{"slug": "foundry-agent-webapps-cosmos-or-azure-sql-for-backend-state-and-when", "title": "Foundry Agent Webapps: Cosmos or Azure SQL for Backend State, and When?", "summary": "A developer writing on geekindata.com argues that the Cosmos-versus-Azure SQL debate for Microsoft Foundry agent webapps conflates two separate storage planes: app-owned backend state, which teams can back with Cosmos or Azure SQL behind a frozen API contract, and Foundry platform stores such as agents, threads, files, knowledge and platform memory, which stay on Foundry. The post recommends Cosmos for document-style message bags and sample velocity, and Azure SQL with EF Core for relational product state, while warning against treating sample Cosmos defaults as a platform mandate or migrating Foundry platform stores alongside the shell database.", "body_md": "I used AI tools to help draft and edit this post. I checked the facts and the wording, and the original lives at [geekindata.com](https://www.geekindata.com/blog/47-foundry-webapp-cosmos-vs-sql). The diagrams are on that page.\n\n**Key takeaways**\n\nCommunity threads keep asking why Microsoft RAG chatbot samples push Cosmos for chat history when a small Azure SQL database would also store messages. Fair question. Document stores map cleanly to message bags, Learn walkthroughs ship fast, and Cosmos shows up in the diagrams people copy.\n\nThat question is **context**, not the whole thesis for a Microsoft Foundry agent webapp. Published agent shells often leave durable product history with your backend. The records your backend writes for the product are your tables. Agents, threads, files, knowledge/Search, and platform memory stay on Foundry. The real decision is which engine backs the **app-owned** plane behind one product API.\n\n**Named model: API stays; store moves**\n\n*Figure 1. Named model: API stays; store moves. Freeze the wire contract. Move only app-owned collections. Leave Foundry platform stores alone.*\n\nMost Cosmos-versus-SQL arguments fail because they mix two planes.\n\n**App-owned backend state** is what your agent webapp API persists for the product: collections A to D (records keyed by id, an index, and an append-only log). That plane is yours to put on Cosmos, Azure SQL, or something else. Callers care about routes and JSON, not which Azure SKU sits under the repository.\n\n**Foundry platform stores** are what the service owns: agent definitions and tools, threads and runs, files and knowledge (including Search grounding), and platform memory. Those stay on Foundry. Shipping a Cosmos-to-SQL cutover for the shell's app-owned collections does not mean you re-home platform threads into your App Service database.\n\nFigure 2 draws the boundary. The engine debate applies to the left column only.\n\n*Figure 2. Two store planes. Cosmos versus Azure SQL is a decision about app-owned backend state. Conflating the planes is how forum debates talk past each other.*\n\nAsk the Reddit question out loud, then narrow it.\n\nCosmos answers (1) often. Message documents are natural, partitioning tutorials are ready, and the architecture diagram looks like the Learn walkthrough. Teams then treat that default as a platform law.\n\nMicrosoft Foundry changes the second half. When a published agent experience leaves multi-turn product history with your backend, the shell API becomes the product history plane whether you like Cosmos or not. Community deploy notes already describe persisting threads and messages in Cosmos **or** Postgres/SQL behind the webapp API. Ownership is not optional. The engine still is.\n\nSo keep the sample default as **context**. Use it to explain why Cosmos appears in diagrams. Do not use it as the ADR for every app-owned table.\n\nFigure 3 is the decision card for the app-owned plane.\n\n*Figure 3. When Cosmos, when Azure SQL. Document bags and sample velocity favor Cosmos. Relational product state and a frozen HTTP cutover favor Azure SQL + EF Core.*\n\n**Prefer Cosmos when**\n\n**Prefer Azure SQL (+ EF Core) when**\n\n**Never**\n\nDefaults are not destiny. Requirements are.\n\nA cutover like this can start when app-owned state sits on Cosmos and a team wants relational ops and one wiring path. The decision is not \"Cosmos is wrong for every chat bag.\" It is \"these collections want relational ops and one wiring path.\"\n\nShip the cutover as **API stays; store moves**:\n\nA temporary bridge can help during migrate. A permanent two-store product is how wiring drifts return. Leave Foundry platform stores alone the entire time.\n\n**Treating sample Cosmos as a Foundry mandate.**\n\nLearn diagrams are teaching aids. Your product state contract is an ADR.\n\n**Moving Foundry platform stores with the shell database.**\n\nAgents, threads, files, knowledge, and platform memory are not more collections on your migration checklist.\n\n**Changing JSON shapes during the engine swap.**\n\nThen every caller bug looks like a database bug. Freeze the wire format first.\n\n**Env drift: Cosmos in one environment, SQL in another.**\n\nEnvironment-only failures follow. One repository wiring path after cutover.\n\n**SQL firewall blocking EF before listen.**\n\nLocal startup never reaches \"API is up\" if migrations cannot connect. Open the firewall path before you chase SPA timeouts.\n\n**Dual-writing forever.**\n\nA temporary bridge is fine. A permanent two-store product reopens the drift you just closed.\n\n**Use as-is**\n\n**Adapt before you use**\n\nDo not rip Cosmos out of a pure message-bag prototype that has no relational pressure just to match this note. Do not \"fix chat history\" by migrating Foundry threads into your SQL database. Do not leave Cosmos credentials in prod config after the app-data path is gone.\n\nSources (community grounding): [Why does MS recommend Cosmos for RAG chat history vs Azure SQL?](https://www.reddit.com/r/AZURE/comments/1d3dx54/azure_rag_architecture/), [Foundry published app / store behavior and backend-owned multi-turn state](https://www.reddit.com/r/AZURE/comments/1q8nw1h/azure_ai_foundry_new_agents_project_endpoint_vs/), [Deploy Foundry agents: persist threads in Cosmos or Postgres/SQL behind your API](https://www.reddit.com/r/AZURE/comments/1p67vdu/deploy_foundry_agents/), [Anyone here using Cosmos DB?](https://www.reddit.com/r/AZURE/comments/1sl05mj/anyone_here_using_cosmosdb/).\n\nSample defaults explain Cosmos in the diagram. Your agent webapp still decides where product state lives. Keep two planes honest. Keep one product API stable. Move only what you own.", "url": "https://wpnews.pro/news/foundry-agent-webapps-cosmos-or-azure-sql-for-backend-state-and-when", "canonical_source": "https://dev.to/geekindata/foundry-agent-webapps-cosmos-or-azure-sql-for-backend-state-and-when-kj1", "published_at": "2026-11-29 16:34:12+00:00", "updated_at": "2026-11-29 16:45:53.538772+00:00", "lang": "en", "topics": ["ai-agents", "ai-infrastructure", "ai-tools", "developer-tools"], "entities": ["Microsoft", "Microsoft Foundry", "Azure Cosmos DB", "Azure SQL", "Entity Framework Core", "geekindata.com"], "also_reported_by": [], "takeaway": "Keep the agent webapp's HTTP contract fixed and migrate only app-owned collections from Cosmos to Azure SQL with EF Core, leaving Foundry platform stores (agents, threads, files, knowledge, memory) untouched.", "recommendation": {"advice": "When moving an agent webapp's app-owned state to Azure SQL, freeze the API contract, migrate only your own collections, and never re-home Foundry platform threads or memory.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/foundry-agent-webapps-cosmos-or-azure-sql-for-backend-state-and-when", "markdown": "https://wpnews.pro/news/foundry-agent-webapps-cosmos-or-azure-sql-for-backend-state-and-when.md", "text": "https://wpnews.pro/news/foundry-agent-webapps-cosmos-or-azure-sql-for-backend-state-and-when.txt", "jsonld": "https://wpnews.pro/news/foundry-agent-webapps-cosmos-or-azure-sql-for-backend-state-and-when.jsonld"}}