Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 33 ยท Practice and Review

Medusa Interview Questions

Prepare for Medusa interviews: architecture, modules vs plugins, workflows, links, Medusa 1 vs 2, events, scaling and security, with short answers and runnable stand-ins.

An interview about Medusa is rarely about memorizing option names. Interviewers want to hear that you understand why the framework is split into modules, why side effects live in workflows, and what can go wrong in production. This page collects the questions that come up most, grouped by topic, each with a short answer you could say out loud and a pointer to the lesson that explains it in depth.

Medusa itself needs a Node server and Postgres, so it cannot run on this site; real Medusa code in this lesson is read-only. Two stand-ins in plain Node.js model the ideas behind two classic questions (dependency injection with module isolation, and rate limiting). They are teaching models, not Medusa's code. Treat details such as exact option names as things to confirm in the current documentation, since they change between releases.

flowchart TD
    Q["Interview topic"] --> A["Architecture<br/>modules, container"]
    Q --> B["Behavior<br/>workflows, events"]
    Q --> C["Data<br/>links, query"]
    Q --> D["Operations<br/>scaling, security"]

Four areas cover most questions; answer each with a rule and an example.

Architecture

What is Medusa, in one sentence? An open-source, Node.js commerce framework that provides commerce modules (products, carts, orders, payments and more), a Store API, an Admin API and an admin dashboard, and lets you extend all of it with your own modules, routes, workflows and subscribers. It is headless: it has no built-in storefront, so you bring your own front end. See What Is Medusa?.

What is the difference between Medusa 1 and Medusa 2? Medusa 2 was rebuilt around isolated modules and workflows. In version 1 the core was a single codebase with services sharing database entities and extended through plugins and entity overrides; in version 2 each commerce area is a module with its own data models, and customizations use custom modules, links, workflows and file-based routes. Say that the two are not drop-in compatible and that migrating means re-implementing customizations. Be careful about claiming more detail than you know.

What is a module? A self-contained package of functionality: data models, a service that exposes business logic, and a definition registered in medusa-config.ts. A module owns its tables, and other modules never query them directly. See Architecture: Modules, Workflows and the Container.

Modules versus plugins? A module is one unit of functionality with its own data. A plugin is a distribution package that can bundle modules, API routes, workflows, subscribers, jobs and admin extensions so they can be installed together and reused across projects. The module is the building block; the plugin is how you ship a set of them.

What does the container do? It is a dependency-injection registry. Services, the query helper, the logger and the event bus are registered under names, and your code asks for them with container.resolve("name"). This keeps routes, steps and subscribers decoupled from construction details and lets tests swap implementations.

Walk me through a request. A request hits a route handler (after middleware such as authentication and validation). The handler should do little: it runs a workflow or reads data with query. The workflow's steps call module services. Modules read and write their own tables. Events emitted along the way reach subscribers, which run after the response or in a worker.

How do you add a custom data model? Define it with model.define("review", { ... }) inside a custom module, build a service class from it with MedusaService, register the module in the config, generate a migration and run it. See Custom Modules and Data Models.

TypeScript
import { model } from "@medusajs/framework/utils"

export const Review = model.define("review", {
  id: model.id().primaryKey(),
  rating: model.number(),
  comment: model.text().nullable(),
})

Why can't a model have a foreign key to the product table? Modules are isolated so that each can be replaced, scaled or tested alone. A direct foreign key would couple the review module to the product module's schema. Instead you store a link.

What is a module link? A relationship between records of two different modules, stored in a dedicated link table that you define with defineLink. You can query across a link with query.graph, and you can attach extra columns to it. See Module Links.

TypeScript
import { defineLink } from "@medusajs/framework/utils"
import ProductModule from "@medusajs/medusa/product"
import ReviewModule from "../modules/review"

export default defineLink(
  ProductModule.linkable.product,
  ReviewModule.linkable.review,
)

What does query.graph give you? A way to read data across modules: you name an entity, list the fields (including linked entities such as reviews.*), add filters and pagination, and Medusa joins the results from the separate modules for you. See Query: Fields, Filters and Pagination.

How would you avoid an N+1 problem? Do not loop over products and fetch reviews one by one. Ask for the linked data in a single query.graph call, select only the fields you need and paginate.

Workflows and events

Why workflows instead of calling services in a route? A workflow is a series of steps with defined inputs and outputs, and each step can have a compensation function. If step four fails, steps one to three are undone. A plain chain of service calls leaves half-finished state. Workflows also give you retries, hooks for others to extend the flow and the option to run long processes asynchronously. See Workflows and Steps.

What is a compensation function? The undo for a step. It receives data the step returned for this purpose (for example the id of a record it created) and reverses the effect. It must be safe to run more than once. See Compensation, Rollback and Long-Running Workflows.

TypeScript
const createReviewStep = createStep(
  "create-review",
  async (input: { rating: number }, { container }) => {
    const reviews = container.resolve("review")
    const review = await reviews.createReviews(input)
    return new StepResponse(review, review.id)
  },
  async (reviewId, { container }) => {
    if (!reviewId) return
    await container.resolve("review").deleteReviews(reviewId)
  },
)

How do you change what a built-in workflow does? Use its hooks when it offers one, rather than copying the whole flow. A hook lets you run your own code at a defined point, for instance to validate or to store extra data. See Hooks and Built-in Workflows.

Events: what guarantees do you get? Treat delivery as at least once. A subscriber may see the same event twice, so handlers must be idempotent, for example by recording processed ids or by making the write an upsert. The local event bus is fine for development; production uses the Redis-backed bus so events survive restarts and work across instances. See Events and Subscribers.

Subscriber or workflow hook? Use a hook when your code must run inside the flow and may need to fail it. Use a subscriber for work that happens afterwards and must not slow or break the main flow, such as sending an email.

Dependency injection and isolation (stand-in)

Interviewers often ask what the container buys you and how isolation is enforced. The first stand-in builds a tiny container with named registrations and a guard that stops one module from reaching into another's private services.

Node.js A container with module isolation

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The real container is richer (scopes per request, many built-in registrations), but the interview-worthy points are visible: one place to look things up by name, lazily created singletons, and boundaries that make accidental coupling an error.

Scaling and operations

How do you scale a Medusa backend? Run it in two modes: server instances that handle HTTP, and worker instances that run subscribers, scheduled jobs and long-running workflows. Put Postgres, Redis and file storage outside the instances so you can add more of either kind. Disable the admin on the worker and on server instances that do not need it. See Deploying Medusa.

Why does Redis matter? It backs the event bus, the workflow engine for long-running workflows, caching and locking. Without it, events and async workflow state live in one process's memory and are lost on restart or invisible to other instances.

A scheduled job runs twice in production. Why? Every instance that runs jobs will run them. Either run jobs only in the worker instance, or make the job safe to run concurrently with a lock or an idempotent design. See Scheduled Jobs.

What would you check first for slow list pages? Field selection (are you loading everything?), pagination, missing database indexes on filtered columns, N+1 patterns in your own routes and whether caching makes sense. See Security and Performance.

Security

Are publishable API keys secrets? No. They identify a sales channel for the storefront and are visible in browser code. The secret ones are JWT_SECRET, COOKIE_SECRET, database and Redis credentials and Admin API tokens. Never expose those to the browser.

How do you protect a custom route? Add the authentication middleware for the right actor type (for example user for admin routes or customer for store routes), validate the body with a schema, never trust ids from the client without checking ownership and return Medusa's typed errors instead of leaking stack traces. See Custom API Routes and Middleware.

How do you handle payment webhooks safely? Verify the signature against the raw body, reject old timestamps if the provider sends them and process events idempotently. See Webhooks and Signatures and Payment Providers.

Rate limiting (stand-in)

A common follow-up is "how would you stop one client from hammering your API?" Medusa does not ask you to hand-write this in every route; a gateway, a reverse proxy or a middleware usually does it. The second stand-in shows the token bucket idea with an injected clock so the output is deterministic.

Node.js A token bucket rate limiter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Each client has a bucket of three tokens that refills one token per second. The fourth immediate request fails, client B is unaffected, and after two seconds client A has earned two requests back. For a deeper treatment of limits and abuse, see Shop Security.

How to answer well

  • Lead with the rule, then the reason. "Modules are isolated, so we use links" beats a list of API names.
  • Mention failure. What happens when step three fails, when an event arrives twice, when Redis is down?
  • Be honest about versions. If you used Medusa 1 and are learning 2, say so and describe the differences you know.
  • Have one story. Prepare a short example from a project, such as a review module with a link, a workflow and a moderation route (see Project: A Product Reviews Module).

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why are modules not allowed to have foreign keys into each other's tables?

    Isolation lets each module own its schema and be swapped or scaled alone. Links store relationships between modules without coupling their tables.
  2. 2. A subscriber for an order event sent two emails for one order. What is the most likely cause and fix?

    Event delivery is at least once. Record processed event ids or the sent state so a repeated event does nothing the second time.
  3. 3. Which of these is safe to expose in browser code?

    The publishable key only scopes a storefront to sales channels. The others grant control and must stay on the server.
  4. 4. What is the best reason to use a workflow instead of several service calls in a route?

    Compensation and hooks are the main benefits. A plain chain leaves partial state behind when a later call fails.
  5. 5. In production, what separates server instances from worker instances?

    Splitting the two modes keeps heavy background work from slowing requests and lets you scale each side independently.

Summary

  • Explain Medusa through its rules: modules own data, links connect modules, workflows own side effects, events are at-least-once.
  • Modules are the building blocks; plugins are how bundles of them are shipped.
  • Workflows with compensation beat plain service chains because failures are undone step by step.
  • Run server and worker modes separately in production, with Redis and external storage, and keep secrets out of browsers.
  • Publishable keys are not secrets; JWT and cookie secrets are.

Finally, keep the quick-reference page open while you build: Medusa Cheat Sheet.