Skip to content

Commit c42bd5e

Browse files
lio-pBlargian
andauthored
Apply suggestions from code review
Co-authored-by: Shaun Struwig <[email protected]>
1 parent 9af4796 commit c42bd5e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

docs/cloud/bestpractices/multitenancy.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ title: 'Multi tenancy'
55
description: 'Best practices to implement multi tenancy'
66
---
77

8-
On a SaaS data analytics platform, it is common for multiple tenants, such as organizations, customers, or business units, to share the same database infrastructure while maintaining logical separation of their data. This allows different users to securely access their own data within the same platform
8+
On a SaaS data analytics platform, it is common for multiple tenants, such as organizations, customers, or business units, to share the same database infrastructure while maintaining logical separation of their data. This allows different users to securely access their own data within the same platform.
99

10-
Depending on the requirements, they are different ways to implement multi-tenancy. Below is a guide on how to implement them with ClickHouse Cloud.
10+
Depending on the requirements, there are different ways to implement multi-tenancy. Below is a guide on how to implement them with ClickHouse Cloud.
1111

1212
## Shared table {#shared-table}
1313

@@ -21,13 +21,13 @@ This method is particularly effective for handling a large number of tenants.
2121

2222
However, alternative approaches may be more suitable if tenants have different data schemas or are expected to diverge over time.
2323

24-
In extreme cases where there is a significant gap in dataset sizes, imagine one tenant with petabytes of data alongside many smaller tenants with only a few gigabytes. Query performance for smaller tenants may be impacted. Note, this issue is largely mitigated by including the tenant field in the primary key.
24+
In extreme cases where there is a significant gap in dataset sizes query performance for smaller tenants may be impacted - imagine one tenant with petabytes of data alongside many smaller tenants with only a few gigabytes. Note, this issue is largely mitigated by including the tenant field in the primary key.
2525

2626
### Example {#shared-table-example}
2727

2828
This is an example of a shared table multi-tenancy model implementation.
2929

30-
First, let's create a shared table with a field `tenant_id` that included in the primary key.
30+
First, let's create a shared table with a field `tenant_id` included in the primary key.
3131

3232
```sql
3333
--- Create table events. Using tenant_id as part of the primary key
@@ -89,7 +89,7 @@ GRANT user_role TO user_1
8989
GRANT user_role TO user_2
9090
```
9191

92-
Now you can connect as `user_1` and run a simple select. Only rows from the tenant 1 are returned.
92+
Now you can connect as `user_1` and run a simple select. Only rows from the first tenant are returned.
9393

9494
```sql
9595
-- Logged as user_1
@@ -109,7 +109,7 @@ FROM events
109109

110110
In this approach, each tenant’s data is stored in a separate table within the same database, eliminating the need for a specific field to identify tenants. User access is enforced using a [GRANT statement](/sql-reference/statements/grant), ensuring that each user can access only tables containing their tenants' data.
111111

112-
Using separate tables is good choice when tenants have different data schemas.
112+
> **Using separate tables is a good choice when tenants have different data schemas.**
113113
114114
For scenarios involving a few tenants with very large datasets where query performance is critical, this approach may outperform a shared table model. Since there is no need to filter out other tenants’ data, queries can be more efficient. Additionally, primary keys can be further optimized, as there is no need to include an extra field (such as a tenant ID) in the primary key.
115115

@@ -171,15 +171,15 @@ CREATE USER user_1 IDENTIFIED BY '<password>'
171171
CREATE USER user_2 IDENTIFIED BY '<password>'
172172
```
173173

174-
Then `GRANT SELECT` privileges on the correponding table.
174+
Then `GRANT SELECT` privileges on the corresponding table.
175175

176176
```sql
177177
-- Grant read only to events table.
178178
GRANT SELECT ON default.events_tenant_1 TO user_1
179179
GRANT SELECT ON default.events_tenant_2 TO user_2
180180
```
181181

182-
Now you can connect as `user_1` and run a simple select on the correct. Only rows from the tenant 1 are returned.
182+
Now you can connect as `user_1` and run a simple select from the table corresponding to this user. Only rows from the first tenant are returned.
183183

184184
```sql
185185
-- Logged as user_1
@@ -199,7 +199,7 @@ FROM default.events_tenant_1
199199

200200
Each tenant’s data is stored in a separate database within the same ClickHouse service.
201201

202-
This approach is useful if each tenant requires a large number of tables and possibly materialized views, and has different data schema. However, it may become challenging to manage if the number of tenants is large.
202+
> **This approach is useful if each tenant requires a large number of tables and possibly materialized views, and has different data schema. However, it may become challenging to manage if the number of tenants is large.**
203203
204204
The implementation is similar to the separate tables approach, but instead of granting privileges at the table level, privileges are granted at the database level.
205205

@@ -269,15 +269,15 @@ CREATE USER user_1 IDENTIFIED BY '<password>'
269269
CREATE USER user_2 IDENTIFIED BY '<password>'
270270
```
271271

272-
Then `GRANT SELECT` privileges on the correponding table.
272+
Then `GRANT SELECT` privileges on the corresponding table.
273273

274274
```sql
275275
-- Grant read only to events table.
276276
GRANT SELECT ON tenant_1.events TO user_1
277277
GRANT SELECT ON tenant_2.events TO user_2
278278
```
279279

280-
Now you can connect as `user_1` and run a simple select on the correct. Only rows from the tenant 1 are returned.
280+
Now you can connect as `user_1` and run a simple select on the events table of the appropriate database. Only rows from the first tenant are returned.
281281

282282
```sql
283283
-- Logged as user_1
@@ -297,7 +297,7 @@ FROM tenant_1.events
297297

298298
The most radical approach is to use a different ClickHouse service per tenant.
299299

300-
This less common method would be a solution if tenants data are required to be stored in different regions - for legal, security or proximity reasons.
300+
> **This less common method would be a solution if tenants data are required to be stored in different regions - for legal, security or proximity reasons.**
301301
302302
A user account must be created on each service where the user can access their respective tenant’s data.
303303

@@ -348,7 +348,7 @@ Then `GRANT SELECT` privileges on the correponding table.
348348
GRANT SELECT ON events TO user_1
349349
```
350350

351-
Now you can connect as `user_1` on the service for tenant 1 and run a simple select on the correct. Only rows from the tenant 1 are returned.
351+
Now you can connect as `user_1` on the service for tenant 1 and run a simple select. Only rows from the first tenant are returned.
352352

353353
```sql
354354
-- Logged as user_1

0 commit comments

Comments
 (0)