7
← Back to Pattern Arsenal
creational

Abstract Factory

good to-know

Stage 1: Problem

The Problem

You are building a multi-tenant SaaS platform that must support multiple databases. Some tenants use MySQL, others use PostgreSQL. For each database, you need three things that must match:

  1. A Repository — handles CRUD with database-specific SQL dialect
  2. A MigrationRunner — runs schema migrations using the right driver
  3. A Seeder — populates initial data using the correct connection

Right now you only support MySQL. Your PM says: "We signed three PostgreSQL clients this week. And the team in Berlin wants MongoDB support by Q3."

Before reading further: How would you structure this so that adding a new database means implementing one set of components, with no risk of mixing a MySQL repository with a PostgreSQL migration runner?


Confused With a Similar Pattern?

1 / 10 — Problem