Skip to content
James Ross
articlePublished Updated 9 min read

Medusa JS in production: four stores, one Medusa v2 backend and the trade-offs

By James Ross

Four storefronts run on one Medusa JS (v2) backend codebase, built once into a single image and deployed four times, so each brand keeps its own database, Stripe account and admin. The decision that shaped the network was a rejection: a single Medusa instance can serve several storefronts through sales channels, but it shares customers across them, so a signup on one brand tells the shopper they already have an account on another.

One image block replicated into four servers, each with its own database and storefront canopy, showing Medusa JS powering four stores.

What does “one backend, four stores” actually mean?

It means one Medusa JS repository, one build artifact and four isolated runtimes. Nothing in a cart on one brand touches a cart, a customer record or a database on another.

The deployment guide defines two compose files. Content sites get a web container only. Store sites get a web container, a Medusa server, a Medusa worker, PostgreSQL 16 and Redis 7, all from docker-compose.store.yml. The backend image is pinned rather than rebuilt per store: the compose file references ${BACKEND_IMAGE:-cf-backend:latest} with pull_policy: never, so all four stacks run the same bytes.

store A:  web ─ medusa-server ─ medusa-worker ─ postgres ─ redis
store B:  web ─ medusa-server ─ medusa-worker ─ postgres ─ redis
store C:  web ─ medusa-server ─ medusa-worker ─ postgres ─ redis
store D:  web ─ medusa-server ─ medusa-worker ─ postgres ─ redis
                    ▲
        one image, built once on the host

The pinning has an operational consequence: pushing backend code does not rebuild the image. A push redeploys the four stores against the previous cf-backend:latest. The documented process is to run the backend build script on the deploy host after the push and before the redeploy. The trade-off is deliberate — four stacks on one image cannot drift into four slightly different Medusa versions.

The host itself is ordinary: a container with 16 cores and 32 GB of RAM, running Coolify with Docker Compose build packs behind Traefik, with a Cloudflare Tunnel in front and admin behind Cloudflare Access.

Why not one shared Medusa instance?

A single Medusa instance can host several storefronts through sales channels, and that is the cheaper answer on paper: one server, one worker, one database, one upgrade. It fails on identity.

Customers are shared across sales channels. When a shopper who bought on one brand signs up on another with the same email, Medusa answers “already exists”, which quietly discloses that the two brands share an owner. The same instance also puts four brands into one admin dashboard and one Stripe configuration.

Concern One Medusa instance, four sales channels One instance per store, one shared image
Customer records Shared across brands; duplicate-email errors leak the link Isolated per brand
Admin access One dashboard, one permission boundary Separate admin per brand
Payment config One Stripe account and webhook secret Separate Stripe account per brand
Upgrades All brands move at once, or none Build once, redeploy one store first, then the rest
Resource cost Smallest: one server and one worker One server and one worker per store
Operations One deploy, one log stream Four deploys, four log streams, one image

The build plan budgeted about 2 GB of RAM per Medusa instance for the server and worker pair, so roughly 8–10 GB across four stores, plus Postgres and Redis. On a 32 GB host that is affordable, which is what made isolation the cheaper choice in practice as well as the safer one.

Which should you choose?

Choose one shared instance only when the storefronts are genuinely the same business under different skins and cross-brand identity is harmless — a wholesale portal and a retail site, for example, where the same buyer legitimately exists in both. Choose one instance per store when the brands are separate identities, separate legal entities or, as here, separate Stripe accounts and admin audiences. The isolation costs RAM and four deploy targets; the shared instance costs you the ability to say “these brands are not connected”.

The four services inside each store stack

Each store stack is small enough to reason about, which is the point of isolating them. The deployment guide’s compose file runs:

  • web — the Astro storefront and content site, prerendered, with server routes for cart and account.
  • medusa-server — the Medusa v2 application serving the Store API, the Admin API and the custom modules.
  • medusa-worker — the same codebase running background jobs: catalog sync, print-provider orders, notifications.
  • postgres — PostgreSQL 16, one database per store.
  • redis — Redis 7 for events and caching, one instance per store.

The build plan originally proposed one PostgreSQL server with a database per store, and one Redis with a key prefix and database number per store. The deployed shape gives each store its own containers instead. Both are defensible; the deployed version removes a shared failure domain at the cost of a few hundred megabytes.

Admin surfaces are not public. Each Medusa admin sits on a separate hostname behind Cloudflare Access, never on the storefront domain.

How Stripe Tax became a Medusa tax provider

Medusa’s Tax Module delegates calculation to a provider service that implements ITaxProvider; the built-in system provider is a placeholder that does basic arithmetic. Sales tax across US states is not arithmetic, and no maintained Stripe Tax provider existed for Medusa v2 — the one package that had done it was a year stale — so the provider is a small module in the backend.

The implementation, from the module brief:

  1. Register a module service with the identifier stripe-tax in the Tax Module’s providers, and set the US region’s tax region to it.
  2. On getTaxLines, convert each Medusa line item to a Stripe line item in cents: unit price times quantity, a reference of the line item id, and a tax code chosen per product category.
  3. Pass shipping as shipping_cost.amount and the cart address as customer_details.address with address_source: "shipping".
  4. Map Stripe’s tax_breakdown back to Medusa tax lines, with the rate as a percentage and the line item or shipping line id preserved.
  5. Cache an identical request for 10 minutes in a bounded 500-entry LRU, with a 5-second timeout.

The tax codes matter more than they look. General tangible goods use txcd_99999999; apparel uses txcd_30011000. A hat taxed as general goods in a state that treats clothing differently is a wrong number on a real invoice, not a rounding error.

The tests are the specification: a California address with two items and shipping maps to three tax lines with the right ids and rates; a missing postal code returns no lines; a disabled provider returns no lines without making a request; a Stripe error logs once and returns no lines; a cache hit avoids the second fetch; and 19.99 × 3 rounds to 5997 cents.

The failure mode is a business decision, not an engineering one

The build plan’s first rule was to block checkout with a clear message rather than charge zero tax. The implemented provider does the opposite: when Stripe Tax is disabled or the account is not configured, it returns no tax lines, logs once per hour, and lets the order through.

That is a real reversal and it deserves to be named. Blocking checkout protects against under-collecting tax; it also means a store with no registrations yet cannot take a single order. The merchant chose the ability to trade over the guarantee, and the risk moved to them: until a state registration exists in Stripe, that state’s orders collect nothing.

Getting 6,423 variants into Medusa without a transaction that dies

The first full catalog sync on the largest store failed in a way that is easy to misread. The admin sync endpoint dispatched work to a 1.5 GB Redis worker with no progress heartbeat, and createProductsWorkflow was handed 294 products and 5,127 variants in a single transaction. It hung, then the worker ran out of memory. From the outside it looked like a stuck job, not an oversized one.

The fix was bounded batching plus a resumable record of what had already happened:

  1. Split creates into batches of 25 products, roughly 400 variants per transaction.
  2. Link each product to its print-provider product immediately after its batch, so a partial run leaves consistent state.
  3. Write created_count, updated_count, failed_count, a phase and a heartbeat timestamp to a sync log after every batch.
  4. Before deciding create or update, look up the product by handle. If it exists from an interrupted run without a provider link, take the update path, reconcile variants by SKU, and repair the link.
  5. Run the sync inside the 4 GB backend container instead of the small worker, so memory is not the constraint.

The result on the two largest stores: 294 created, 76 updated, 0 failed, 370 products total; then 242 created, 63 updated, 0 failed, 305 products total.

The rule that came out of it

Any workflow that touches more than a few hundred variants needs three properties before it runs against production: a batch size that is a constant in the code, a per-batch progress record that survives a restart, and an idempotent path that recognises its own half-finished work. The sync has all three now. It did not have any of them on the first run.

Keeping the storefront, the feed and the mockups in agreement

Catalog state is only useful if every surface reads the same version of it. Three surfaces matter here: the product page, the Merchant feed, and the product images.

The publish gate is binary. After the sync, each product either passes or fails on file size, DPI, transparency, embroidery palette and whether provider mockups exist. The two big stores published at 370 passed and 0 failed, and 305 passed and 0 failed. Nothing goes live on a maybe.

The nightly sync disables discontinued and out-of-stock variants, so a variant disappears from the storefront and from the feed in the same run. That is the whole reason the feed is generated from Medusa rather than from a spreadsheet: two sources would disagree within a week.

Images follow a fixed order. images[0] and the product thumbnail are always the clean product mockup; the lifestyle photo is always images[1], with 400w, 800w and 1200w WebP variants. When older runs had put a lifestyle photo first, 96 products across the four stores had to be reordered.

What broke and what we changed

One transaction, 5,127 variants. Covered above: batches of 25, heartbeats, idempotent recovery, and moving the run out of the small worker. This was the change that made the rest of the catalog work possible.

Mugs printed on the wrong side of the wrap. The print provider’s mug template is a 2,700 × 1,050 full wrap. Artwork was placed with mode: "center", which puts the print in the middle of the wrap — on the side opposite the handle in the provider’s default camera view. Tumblers used a 0.42 width ratio and wrapped around the cylinder edge. The layout moved to a pair at ratio 0.31, centred at 0.25 and 0.75 of the width, so the mug reads front-on from either side; the tumbler ratio dropped to 0.30. 138 print files were regenerated — 66 on one store, 72 on the other — along with their mockups.

Thumbnails pointing at raw preview files. 59 products on one store and 180 on the other still had thumbnail set to a raw *_preview.png from an earlier apply step, because those products were skipped when they already existed at the provider. The fix pointed thumbnail at images[0] and appended a cache-busting ?v=2 to every mockup and lifestyle URL in Postgres, because the CDN was still serving the old bytes.

A tax provider that did not exist. The plan assumed a package would do it. The package was a year stale against Medusa v2’s provider interface, so the module was written and tested instead. Budgeting for “write the tax provider” rather than “install the tax provider” would have been the honest estimate.

An image pin that hides a stale deploy. pull_policy: never means a code push alone redeploys the old image. The runbook now says build first, deploy second. This is the classic cost of treating a container tag as a version.

Frequently asked questions

Is Medusa v2 multi-store?

Yes, in the sense that one Medusa instance can serve several storefronts through sales channels, each with its own publishable key and product assortment. It is not multi-tenant for customers: a customer record is visible across sales channels in the same instance, which is why separate brands usually get separate instances.

Do four storefronts on one backend share customer accounts?

Not in this network. Each store runs its own Medusa instance with its own database, so an account on one brand does not exist on another and nothing about a shopper leaks between them. The sharing is at the code and image level, not the data level.

How much RAM does a Medusa v2 store need?

The build plan budgeted about 2 GB per store for the Medusa server and worker together, so roughly 8–10 GB for four stores before Postgres and Redis. That figure is a planning estimate from the build plan, not a measured ceiling; a store with heavy background jobs will want headroom.

Why use Stripe Tax instead of writing state tax rates?

Rate tables go stale, and the obligation is per registration, not per state. Stripe Tax knows the destination rules and the product tax codes, and Medusa's Tax Module is designed to delegate exactly this calculation to a provider. The cost is a per-calculation fee and a dependency on Stripe being reachable at checkout.

What happens at checkout if Stripe Tax is turned off?

The provider returns no tax lines, logs once per hour and lets the order complete with zero tax. That is a deliberate choice so a store can trade before its registrations exist. It also means the merchant, not the software, is responsible for not selling into a state where they are registered and collecting nothing.

Can one backend image really serve four different stores?

Yes, because the differences live in configuration and data, not code: brand config, catalog, Stripe keys, notification templates and the database connection. The image is identical; the environment and the database are not. A code change can go to all four at once, which is the point of building it once.

How do you keep a large catalog sync from duplicating products?

Match on a stable natural key before creating anything. This sync looks up the product by handle, reconciles variants by SKU and repairs missing provider links when it finds a product from an interrupted run. Duplicates come from creating first and reconciling later.