avioxtechnologies.com ↗Subscribe to the Dispatch

Research paperAVX-R-2026-02Software architecture

One Application, Many Tenants: Three Multi-Tenancy Architectures in Laravel

Database per tenant, a shared schema with tenant identifiers, or a dedicated package. A comparative study of isolation, cost and operational complexity.

By Aviox Blogs Engineering5 min read
Three groups of database cylinders on midnight blue — separate cylinders on each side, and one large ember cylinder in the middle shared by six tenants.
Aviox Research LibraryAVX-R-2026-02
On this page · 05 sections
  1. Abstract
  2. Key findings
  3. Introduction
  4. Approach 1: A separate database per tenant
  5. Questions

Abstract

Multi-tenancy lets a single application serve many customers while keeping their data isolated and their configuration independent. The architecture chosen early shapes security, cost and operations for the life of a SaaS product. This paper compares three approaches in Laravel: a separate database per tenant, selected per request by middleware; a shared database where every row carries a tenant identifier; and adopting a dedicated tenancy package. For each we present a reference implementation and evaluate isolation strength, infrastructure cost, migration and backup complexity, and exposure to noisy-neighbour effects.

Key findings

  1. 01

    Database-per-tenant gives the strongest isolation and simplest per-customer backup, at the highest operational cost.

  2. 02

    A shared schema is the cheapest to run but depends on every query being scoped — global scopes are essential.

  3. 03

    Tenant resolution belongs in middleware, before any query runs.

  4. 04

    A maintained package removes boilerplate; the original guide’s choice, hyn/multi-tenant, is no longer actively maintained.

Introduction

Multi-tenancy is an architectural approach that allows a single application to serve multiple clients — tenants — while maintaining data isolation and allowing per-tenant customization. In a Laravel application, it requires deliberate design: where tenant data lives, how each request discovers its tenant, and how every query is kept within the right boundary.

Diagram comparing three tenancy models: separate databases with one per tenant; a single shared database whose rows carry a tenant_id column; and a package layer that manages tenant resolution and databases on the application's behalf.

Three models, trading isolation against operational simplicity.

Approach 1: A separate database per tenant

Each tenant receives its own database, giving complete data segregation. This suits tenants that require strong isolation or need to scale independently.

Tenant registry

A central table records each tenant and the database that holds its data:

public function up(): void
{
    Schema::create('tenants', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('domain')->unique();
        $table->string('database')->unique();
        $table->timestamps();
    });
}
database/migrations/xxxx_xx_xx_create_tenants_table.php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Tenant extends Model
{
    protected $fillable = ['name', 'domain', 'database'];
}
app/Models/Tenant.php

Switching connections per request

Middleware resolves the tenant from the request’s host and points the connection at that tenant’s database before any query runs:

namespace App\Http\Middleware;

use App\Models\Tenant;
use Closure;
use Illuminate\Support\Facades\DB;

class TenantMiddleware
{
    public function handle($request, Closure $next)
    {
        $tenant = Tenant::where('domain', $request->getHost())->firstOrFail();

        config(['database.connections.mysql.database' => $tenant->database]);
        DB::purge('mysql');
        DB::reconnect('mysql');

        return $next($request);
    }
}
app/Http/Middleware/TenantMiddleware.php

Apply it to every route that serves tenant data:

Route::middleware(TenantMiddleware::class)->group(function () {
    Route::get('/dashboard', DashboardController::class);
    // …all tenant routes
});
routes/web.php

Keep the registry separate

In production the tenants table usually lives on its own central connection, so tenant resolution never depends on the database being switched to.

Originally published at Aviox Blogs engineering handbook.

Written by

Aviox Blogs Engineering

Field notes, deployment guides and research from the engineers who build web, cloud and mobile products at Aviox Blogs.

Insights & Understanding

Frequently Asked Questions

Answers to common questions regarding this article's topic, architecture, and practical applications.

More from the library

Everything new
Two circular peers on a midnight-blue field joined by a fan of fine lines with one ember line through the centre, and a dotted arc rising to a diamond-shaped relay above.

Research

Peer-to-Peer by Design: How WebRTC Negotiates a Real-Time Connection

How two browsers that cannot see each other establish a direct, encrypted media channel: capture, signaling, SDP offer and answer, and ICE with STUN and TURN.

Aviox Blogs Engineering · 7 min read
A flame graph of stacked grey bars on near-black, with one bar in the middle of the stack highlighted in ember.

Research

Measure Before You Optimize: A Profiling-Led Approach to React Performance

A method for React performance work that starts with measurement: how rendering really works, how to read the Profiler, and which techniques fix which problems.

Aviox Blogs Engineering · 7 min read

The Dispatch · Newsletter

Engineering notes, delivered occasionally.

New deep dives, research and what’s next in AI and software — one calm email when there’s something worth reading. Unsubscribe in one click.

sales@avioxtechnologies.comOne email when there’s something worth reading · Never sold or shared