Other

Put the Mongo-to-SQL toggle at the contract, not inside the shared package

DEV Community: #dotnet Tummala Krishna Kishore
Other

When one team owns MongoDB and another owns SQL behind the same Azure Function App, the obvious if (useSql) belongs at a narrow storage contract, not inside the shared package. The author lays out one DI registration that reads the flag, per-deployment-slot switching, contract tests for both implementations and shadow reads instead of dual writes.

Key points

  • Keep the feature behind a 4-5 method storage contract (GetByCustomer, Save, MarkProcessed) rather than a repository exposing filters or IQueryable.
  • Read the Mongo/SQL flag in exactly one place: the factory or DI registration in the shared package; the Function App never sees it.
  • Design the contract around the domain object the app consumes and make the SQL side reassemble nested documents once, in a single tested mapper.
  • Switch per deployment slot with one app setting instead of a per-request or per-tenant flag; add percentages only when a real rollout demands it.
  • Avoid dual writes; use shadow reads that query the new store in the background and log differences without affecting the served result.
  • Agree the contract in one meeting, build the SQL implementation behind it without touching Mongo code, and delete the Mongo path after a full business cycle on SQL.

Why it matters

It decides whether two teams can ship independently or spend months editing the same class: a single seam keeps the flag readable, testable and deletable when the old store goes away.

Real-world use

  • A multi-tenant SaaS API replacing its document store with a relational database while both teams ship in parallel.
  • An Azure Function App that needs to flip storage backends per deployment slot and roll back quickly if reads misbehave.
  • A background worker where a performance-critical query path gets its own contract method so each store can optimise it.
  • A migration where shadow reads compare old and new store results before cutting traffic over.

This summary was generated by the agent from the original post on DEV Community: #dotnet. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message