Support multitenancy
See original GitHub issueSupport multitenancy
I work on Spring-boot+Postgre application which works in multitenant-mode. Namely, we implemented AbstractRoutingDataSource and our solution is based on using ThreadLocal:
public class MyRoutingSource extends AbstractRoutingDataSource {
@Override
protected Object determineCurrentLookupKey() {
return getNameOfTenantFromThreadLocal();
}
// ....
}
Ultimately I would like Shedlock to support the following:
- single
LockProvider
bean (as it is now) - database for each tenant having own
shedlock
table - cache
LockRecordRegistry
be tenant-dependant (i.e.private final Set<String> lockRecords
transform toprivate final Map<Object, Set<String>> lockRecords
whereObject
is tenant identifier (same as inAbstractRoutingDataSource
).
When I tried to supply instance of AbstractRoutingDataSource
to JdbcTemplateLockProvider(myRoutingSource)
then I’ve got runtime exception because initialization of new Bean isn’t bound to any tenant-context and SqlStatementsSource#getDatabaseProductName
is trying to query DB during initialization.
Suggested improvement
- Give option to configuration to rather directly specify database-used OR lazy initialize DB provider name. Example:
private static String getDatabaseProductName(Configuration configuration) {
if (configuration.getPredifnedDatabaseProductName() != null) {
return configuration.getPredifnedDatabaseProductName();
}
return configuration.getJdbcTemplate().execute((ConnectionCallback<String>) connection -> connection.getMetaData().getDatabaseProductName());
}
- Make cache tenant-configurable.
How to use multitenancy right now Workaround solution I came with:
- single
LockProvider
bean - separate database for shedlock which is shared by all tenants
- wrapper util on top of shedlock where I add tenant-name as prefix to lock name
Extra I would like to say thank you for such a nice library!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
SaaS: Single Tenant vs Multi-Tenant - What's the Difference?
Multi-Tenant – Multi-tenancy means that a single instance of the software and its supporting infrastructure serves multiple customers.
Read more >What is multi-tenancy? | Definition from TechTarget
Multi-tenancy is an architecture in which a single instance of a software application serves multiple customers. Each customer is called a tenant.
Read more >Multitenancy - Wikipedia
Software multitenancy is a software architecture in which a single instance of software runs on a server and serves multiple tenants.
Read more >What is multitenancy? - Red Hat
Multitenancy is a software architecture where a single software instance can serve multiple, distinct user groups.
Read more >Definition of Multitenancy - IT Glossary - Gartner
Multitenancy is a reference to the mode of operation of software where multiple independent instances of one or multiple applications operate in a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Documented here https://github.com/lukas-krecan/ShedLock#Multi-tenancy
Yes, that’s why I hesitate to add DB provider to the configuration.