zufflie's avatar

When to decide to use real Multitenancy?

Hey Guys, I am currently doing some personal projects to learn and imitate reality.

Now i am in a thought about a product which i am designing. The broad overview of the product is to match players in soccer leagues to a Club regarding how good they match to the overall team personality (so no hard skills, only soft skills).

Now i am a bit in a thought trouble. Because a Player can registrate, do the soft skills analysis and then search for clubs with that matches his personality in the existing team. They then can apply or be messaged from the club and the Club handles in the software further requirements, like a video call, injury record, etc.

A Club can registrate and invite Team Members to the Club which all can act on Players, search for fitting ones, chat with them etc. Clubs have their own Dashboard, just like Players. A Club can Invite Players to do the soft skill analysis, they could then be opt in to also join the Players Pool afterward.

Is this already a case for multi tenancy or would i just bloat my Software? My first thought was to do a Multi Tenancy Application so every Club has their own Subdomain and Database and the players go back into the shared Database in the Players Pool. Now i question this idea and maybe i could just do a Modular Laravel Approach.. What are your thoughts, currently i am really lost..

0 likes
1 reply
LaryAI's avatar
Level 58

Multitenancy is a software architecture where a single instance of the software runs on a server, serving multiple tenant groups (tenants). In the context of your soccer league matching application, multitenancy would mean that each club could have its own separate environment (like a subdomain and potentially a separate database) within your application.

Deciding whether to implement real multitenancy depends on several factors:

  1. Data Isolation: If clubs require strict data isolation for security or privacy reasons, multitenancy with separate databases might be necessary.

  2. Customization: If clubs need to have significant customization in terms of features, functionality, or appearance, multitenancy can make this easier to manage.

  3. Scalability: If you expect to scale to a large number of clubs, multitenancy can help manage resources more efficiently.

  4. Maintenance and Complexity: Multitenancy can add complexity to your application's codebase and infrastructure. It can make maintenance more challenging if not designed properly.

  5. Cost: Separate databases and subdomains can increase hosting costs.

Given the description of your application, it seems like you might not need full-blown multitenancy. Here's why:

  • Shared Player Pool: Since players are shared across clubs and can be searched and contacted by any club, a single database could suffice.

  • Club Dashboards: Clubs can have their own dashboards and functionalities without needing a separate database. You can use Laravel's authorization and authentication features to ensure that clubs only see their own data.

  • Modularity: A modular approach in Laravel using packages, service providers, and policies can help you separate the logic for different types of users (players vs. clubs) without needing separate databases.

Here's a simplified example of how you might structure your application using a single database:

// Use Laravel's built-in authentication and authorization to handle different roles
Route::middleware('auth:club')->group(function () {
    // Club dashboard routes
    Route::get('/dashboard', 'ClubController@dashboard');
    // Other club-specific routes
});

Route::middleware('auth:player')->group(function () {
    // Player dashboard routes
    Route::get('/dashboard', 'PlayerController@dashboard');
    // Other player-specific routes
});

// Use policies to control access to different models
class ClubPolicy
{
    public function view(User $user, Club $club)
    {
        return $user->belongsToClub($club);
    }
    // Other club-specific authorization logic
}

class PlayerPolicy
{
    public function view(User $user, Player $player)
    {
        return $user->is($player);
    }
    // Other player-specific authorization logic
}

In this example, you would use Laravel's built-in features to manage different user types and their permissions. You can also use scopes on your models to ensure that clubs only interact with their own data.

In conclusion, unless you have a strong requirement for data isolation, significant customization per club, or other specific needs that demand multitenancy, you might be better off starting with a single-tenant application that is well-structured and modular. This approach will likely be simpler to develop and maintain, and you can always refactor to a multitenant architecture later if the need arises.

Please or to participate in this conversation.