Building multi-tenant applications: Tenant URLs

Naming the tenant is one thing. But where to put their stuff? How to namespace resources for different organization?

Different tenant resources paths

Tenant resources have to live somewhere. Let's take a company name Customer and their projects as our example.

The naive approach is to leave the tenant name from the URLs. After all, is it required?

https://example.com/projects/8383

Projects will have some kind of tenant_id so we can still find the tenant and authorize it. However, creating new resources is unbookmarkable as projects/new belongs to all.

Most people might put it as a subdomain:

https://customer.example.com/projects/8383

Pretty nice, customers will have their own domain. Maybe they will even feel special. I like it, except that it conflicts with using subdomains for other things (staging, versioning, assets).

Then we can treat a tenant as a parent resource:

https://example.com/customers/customer/projects/8383

This version is without any issues but it's long. We can shorten it of course from customers to something like a single-letter s or maybe even omit them at all.

Basecamp style

Actually, this is the style of Basecamp's resource URL (authors of Basecamp are also behind the Rails framework Business Class is built upon):

https://example.com/customer/projects/8383

And to me it might be the best one.

I kept it simple in Business Class 2.0 as a parent resource, but I already moved to Basecamp-style URLs in LakyAI.

I wonder what people prefer but I am inclined to use the Basecamp style going forward. Luckily, it's the simplest of changes from the previous style.

Author
Josef Strzibny
A long time Rails developer from the early Rails 2.0 days. Author of Business Class and books like Kamal Handbook and Test Driving Rails.

© Business Class Blog