API / Apache Grails Interview questions
How do you configure multi-tenancy in a Grails application with GORM?
- Choose a multi-tenancy strategy supported by GORM — common approaches include a separate database per tenant, a separate schema per tenant, or a shared table with a discriminator column identifying the tenant on every row.
- Mark domain classes as multi-tenant using GORM's multi-tenancy support, which wires the chosen strategy's tenant-resolution logic into every query and save operation for those classes automatically.
- Implement tenant resolution — typically a class that determines the current tenant from the request context (a subdomain, an authenticated user's tenant ID, an HTTP header), consulted automatically wherever tenant-aware persistence happens.
- Use @CurrentTenant on GORM Data Service methods that should automatically scope their queries to whichever tenant is currently resolved, without the developer manually adding a tenant filter to every single query.
The core value of GORM's built-in multi-tenancy support is that once it's configured, ordinary-looking GORM code — a plain findByX() call or a Data Service method — automatically stays scoped to the correct tenant behind the scenes, rather than every query throughout the application needing an explicit, easy-to-forget tenant filter bolted on by hand.
More Related questions...