Lesson 4.2• 6 min read

Federation and functional partitioning

Splitting databases by function, and what it costs: cross-database joins, foreign keys and uneven growth.

What you will learn

  • Split one database into several along functional boundaries.
  • Name what federation gains: less traffic, smaller working sets and parallel writes.
  • Name what it costs: joins, foreign keys and a domain that outgrows its database.

What is database federation?

Federation (functional partitioning) splits a monolithic database into multiple independent physical databases along domain or functional boundaries.

Instead of a single monolithic database housing users, products, orders, and payments, we provision:

  • Users DB: user_profiles, auth_credentials, settings
  • Catalog DB: products, inventory, categories
  • Orders DB: orders, line_items, shipments
  • Payments DB: transactions, payouts, audit_log

Advantages of functional federation

  • Less traffic per database: Each database sees only its own reads and writes, so there is less to replicate and less replication lag.
  • Smaller working sets: Smaller databases mean more of the data fits in memory (PostgreSQL shared_buffers, MySQL's InnoDB buffer pool), so more reads are cache hits.
  • Parallel writes: With no single primary serializing every write, the databases can accept writes in parallel, increasing throughput.
  • Independent sizing and failure isolation: A busy Orders DB can get bigger hardware than a quiet Users DB, and a runaway query on one database does not exhaust connections on another.

Trade-offs and architectural challenges

While federation is simpler to implement than full horizontal sharding, it introduces fundamental distributed systems constraints:

1. Cross-database joins get harder

Your application must now know which database to read from and write to. In a monolithic database:

SELECT o.id, u.email, p.title 
FROM orders o 
JOIN users u ON o.user_id = u.id 
JOIN products p ON o.product_id = p.id;

Across federated databases, a single SQL join no longer works as is: joining data from two databases needs a server link between them (more complex and slower), or the application performs the join itself with fan-out queries:

  1. Fetch order from Orders DB.
  2. Concurrently fetch user_id from Users DB and product_id from Catalog DB.
  3. Stitch the results in application memory.

2. Loss of referential integrity (foreign keys)

Foreign key constraints cannot reach across separate database servers. Application services or asynchronous event streams must enforce referential integrity.

3. Uneven domain growth

Federation does not help if your schema needs one huge table or function. If most of the traffic lands on one domain (say the Orders DB), federating only buys time; when that database hits its ceiling, you need horizontal sharding. Federation also adds hardware and complexity.

Clients1× instanceLoad balancer2× instancesUsers service4× instancesOrders service4× instancesPayments service4× instancesUsers database1× instanceOrders database1× instancePayments database1× instanceClients1× instanceLoad balancer2× instancesUsers service4× instancesOrders service4× instancesPayments service4× instancesUsers database1× instanceOrders database1× instancePayments database1× instanceClients1× instanceLoad balancer2× instancesUsers service4× instancesOrders service4× instancesPayments service4× instancesUsers database1× instanceOrders database1× instancePayments database1× instance
Figure 2

Federation: one database for each domain.

Follow a request from the clients: the load balancer sends it to the service for its domain, and that service reads and writes only its own database. Each database carries only its own domain’s traffic, so it has less to replicate, keeps more of its data in memory, and takes writes in parallel with the others. The price is that a query joining users with orders now needs two databases.

  • Clients: 1 × Users
  • Load balancer: 2 × Load balancer
  • Users service: 4 × App server
  • Orders service: 4 × App server
  • Payments service: 4 × App server
  • Users database: 1 × Relational database
  • Orders database: 1 × Relational database
  • Payments database: 1 × Relational database
  • Clients sends requests to Load balancer
  • Load balancer sends requests to Users service
  • Load balancer sends requests to Orders service
  • Load balancer sends requests to Payments service
  • Users service sends requests to Users database
  • Orders service sends requests to Orders database
  • Payments service sends requests to Payments database

Key takeaways

  • Each federated database carries only its own domain's reads and writes, so it replicates less, keeps more in memory and fails on its own.
  • A join across databases needs a server link or a fan-out from the application, and foreign keys cannot span databases.
  • If most traffic lands on one domain, federation only buys time: that database will need sharding.
Sources2