Multi-Tenancy

A single VARIO Cloud App instance serves multiple tenants (customers). Each tenant has its own data, credentials, and configuration. Multi-tenancy is built into the framework, but you need to be aware of its implications.

How Multi-Tenancy Works

When your app receives a request (API call or webhook), the framework provides context about which tenant the request belongs to:

const { getTenant, getAccessToken } = require('@vario-software/vario-app-framework-backend/utils/context');

app.apiServer.get('/some-endpoint', async (req, res) =>
{
  const tenant = getTenant();           // e.g., "customer-a"
  const token = getAccessToken();       // Contains tenant info

  // All ErpApi calls automatically use the correct tenant
  const data = await ErpApi.vql('SELECT id FROM article.queryArticles LIMIT 1');

  res.json(data);
});

The tenant is extracted from the access token, which is validated by the framework's authentication middleware. You don't need to pass the tenant explicitly — it's automatically available through the context.

Per-Tenant Token Storage

During installation, each tenant receives its own offline token. The framework stores these per tenant:

The ErpApi class handles this automatically — it retrieves the correct offline token for the current tenant from context.

Data Isolation

Every piece of data in your app must be scoped to the correct tenant:

EAV Data

EAV groups are tenant-scoped by default. When you read or write EAV data, the framework uses the current tenant context:

Local Data

If you store data locally (database, files), include the tenant identifier:

Queue Data

If your queue is shared across tenants, include the tenant ID in queue items:

When processing queue items, use runInContext to set the correct tenant context:

Common Pitfalls

Shared State

Avoid global variables that store tenant-specific data. Use the context system instead:

In-Memory Caches

If you use in-memory caches, include the tenant in the cache key:

Background Processing

When processing items outside of a request context (e.g., timer-based queue processing), make sure to establish the correct tenant context before making ERP API calls.

Testing Multi-Tenancy

To verify tenant isolation:

  1. Install the app on two different test tenants

  2. Configure different settings on each tenant

  3. Trigger syncs on both tenants

  4. Verify that each tenant's data remains separate

  5. Check that credentials and tokens don't cross-contaminate

Last updated

Was this helpful?