How Counterworks set tenant boundaries for cache, S3 and external service settings
The article describes how the Japanese company Counterworks separated tenant data outside the database in its Shop Counter Enterprise (SCE) cloud system for leasing. Each tenant is a customer company, and SCE is a multi-tenant[1] application. Row Level Security[2] protects only the database, so the cache, S3 and external service settings each got their own tenant boundary. Cache keys always include the tenant ID, and the existing Redis access token and session keys were copied under the new prefix in a one-time task during maintenance, not moved, so a rollback stays simple.
S3 keys get a tenant prefix. All tenants share one bucket, and the enterprise_id is the first part of each key, instead of using a bucket per tenant. The class AwsS3KeyFactory adds the prefix automatically to uploads, downloads, deletes and presigned URL[3] issuance, so application code only passes a path. Existing objects were moved under the prefix with aws s3 mv rather than copied, and public objects were given the public-read ACL again.
Settings and credentials that differ per tenant are stored in database tables with one row per tenant: EnterpriseConfiguration for settings and EnterpriseCredential for credentials. Aurora storage encryption is enabled. The OpenID Connect[4] client information is taken from the current tenant's credential, and the Slack notification channel from its configuration.
Sources
-
JPZenn JA
DB以外にも必要だったテナントの境界をどう設けたか(マルチテナント化連載 第7回・DB以外のテナント分離編)



