111 Steps to Building a
Multi-tenanted SaaS in
Edappy started with a single-tenanted internal
system, delivering University-level courses
Node.js - Seneca - Express - MongoDB
The job: Make the platform a multi-tenanted SaaS
“This should be easy”
We started to think about Tenant Provisioning.
“How does it relate to the business model?”
“How will we…monitor it, maintain it or deploy it?”
We will have many small tenants. Some
will be just evaluating, at least at first.
They will be spread internationally and
many will use a free tier.
A few will be large, enterprise tenants.
They will take longer to publish their
content but will have many thousands of
students and many, large courses.
Don’t just think production.
How do I run a multi-tenanted
SaaS in development?
What will my tests look like?
How many processes, containers
and VMs will I need to run?
Share resources where
Isolate only when required.
No new hardware.
Before adding any containers or instances,
maximise every bit of existing
More cost effective.
So we wrote…
seneca-context allows you to set or get any data relating
to a single request at any point in the action chain, even
across transport boundaries
createContext Tenant Registry
There are hundreds of actors
Each actor has 0..* store operations
How do you avoid explicitly setting the
zone for every operation?
Write another Seneca plugin
Intercept all entity actions
Look up the zone/context if not already set
Provision the DB, if not already done
Configure the store plugin
Set the zone and call seneca.prior
Don’t create or read any tenant-specific data on init
Register a tenant record
Create external resources (bucket)
Approximately $0 cost
At least one instance of each service
At least two tenants
Clean database per suite
Each test begins outside the app boundary (SuperTest)
Seneca test actions to perform setup/teardown
We use ELK for aggregated logs across containers and
Log and index tenant ID
Up to a point, adding instances, containers is okay
Large, high value tenants warrant dedicated resources
Limit tenant-specific resources per app instance (DB
Explicit/Manual, Mesos, Kubernetes