A help desk product keeps the articles of many customers in one search server. Each customer is a tenant: its users must find its own articles and nobody else's. This is a multi-tenant architecture, and before the first customer is loaded the team has to choose between two layouts of it. Either all tenants share one table and every query carries a filter on tenant_id, or every tenant gets a table of its own.
This post measures both layouts on Manticore Search 29.9.0 with four cores and 4 GB of memory. The tenants are 99 Stack Exchange sites with 1,610,651 questions and answers between them, from 588 documents in the smallest site to 43,281 in the largest. With a table per tenant, a search by two or three words took a median of 0.63 to 1.24 ms; the same searches in the shared table took 1.43 to 1.91 ms. Eight clients searching at once got 8,765 answers per second from the separate tables and 2,691 from the shared one.
The separate tables cost memory. After a restart the server held 1.571 GiB for them and 72 MiB for the shared table. Writing every tenant table to disk brought that down to 223 MiB, and every further small table added about 1 MiB. At 3,530 tables the 4 GB server was killed for lack of memory, while one shared table held 10,000 small tenants in 35 MiB. Neither layout kept a quiet tenant fast while another tenant ran heavy searches.
TL;DR
- In the shared table design all tenants' documents are in one table and the application adds
tenant_id=Nto every query. In the table per tenant design each tenant has its own table and its own database user. - A search by two or three words took a median of 0.63 to 1.24 ms in a tenant's own table and 1.43 to 1.91 ms in the shared table. A phrase search took 0.92 to 2.52 ms against 4.62 to 8.07 ms.
- Every table costs memory, about 1 MiB for a small one. The 4 GB server was killed at 3,530 tables and needed 80 seconds to start with that many tables and users. One shared table held 10,000 small tenants in 35 MiB and started in 2 seconds.
- The 99 tenant tables held 1.571 GiB after a restart, because tables smaller than 128 MB keep their documents in memory. After
FLUSH RAMCHUNK, the statement that writes them to a file, was run on every table, they held 223 MiB; the shared table held 72 MiB. - The noisy neighbor problem, one tenant's load slowing the others, appeared in both designs. While the largest tenant ran 16 heavy clients, a quiet tenant's median went from 1.24 to 29.32 ms in the shared table and from 0.75 to 15.02 ms with separate tables.
- A tenant filter covers rows, counts and facets. Spelling suggestions, autocomplete and keyword statistics come from every tenant's words, and none of them accepts a filter.
- Ranking differs. For the same tenant, the same query and the same documents, the first 20 results came in a different order for 38 of 199 queries in a small tenant and 123 of 200 in the largest.
- Removing a tenant with
DROP TABLEfreed its disk space at once.DELETEin the shared table hid the rows at once, but the documents stayed in the files until a full merge that took 224.1 s. - A database user per tenant makes Manticore refuse a statement that the application sends to the wrong tenant's table. It checks the application's routing; it is not a reason to give tenants these credentials.
The Two Designs

Both designs store the same documents with the same columns:
CREATE TABLE posts(
title text, body text, tags text,
tenant_id integer, post_id bigint, kind integer,
main_tag string, created timestamp, score integer
);
post_id is the number the document has in the tenant's own system, here the post number on its site. kind tells a question from an answer.
In the shared design there is one such table, and one database user that may read and write it. The application adds the tenant to every statement. Here tenant 5 is a site about drones:
SELECT post_id, title, WEIGHT() w FROM posts
WHERE MATCH('battery output voltage') AND tenant_id=5 LIMIT 20;
In the per-tenant design there are 99 such tables and 99 database users, and the application picks the table and the user:
SELECT post_id, title, WEIGHT() w FROM posts_drones
WHERE MATCH('battery output voltage') LIMIT 20;
In both designs the tenant comes from the server side: from the signed-in session, after the application has checked that the user belongs to that tenant. It never comes from a field of the request. A tenant_id taken from the request lets any user choose somebody else's rows in the shared table. A table name taken from the request does the same wherever one database user can read every table.
The documents are from the Stack Exchange Data Dump (CC BY-SA 4.0), in files dated April 2024: the 99 main sites whose archive is smaller than 50 MiB, without the meta sites that accompany them. One site is one tenant. A document is a question or an answer with the HTML removed and the body cut to 2,000 characters. The three tenants used for single measurements are a small one (2,185 documents, drones), the median one (13,625, amateur radio) and the largest (43,281, gardening).
Manticore ran in Docker on four cores and 4 GB of memory, with authentication on. The client is a Python script on the same host that talks HTTP; every time below is measured in the client and includes the HTTP round trip. The host is shared with other work, so the timings show how the two designs compare and are not a benchmark of the hardware.
Search Time in Each Design
Each cell is the median time of one search, shared table first, the tenant's own table second. One client, after a warm-up pass.
| Search | Small tenant | Median tenant | Largest tenant |
|---|---|---|---|
| Two or three words from the tenant's own question titles | 1.45 / 0.63 ms | 1.43 / 0.80 ms | 1.91 / 1.24 ms |
A word that is common on all sites (time) | 1.58 / 0.76 ms | 1.38 / 0.62 ms | 2.34 / 1.39 ms |
A phrase ("how to") | 4.62 / 0.92 ms | 5.05 / 1.57 ms | 8.07 / 2.52 ms |
| The common word with a facet on the main tag | 2.28 / 0.76 ms | 2.86 / 1.45 ms | 2.99 / 2.88 ms |
| The newest 20 documents, no text | 1.95 / 0.99 ms | 2.59 / 2.27 ms | 2.89 / 3.55 ms |
The tenant's own table was faster in 14 of the 15 cells, and the gap was widest for the phrase. The exception is the listing without text for the largest tenant. The 95th percentile, the time that 95 of 100 searches stayed under, was below 11 ms in every cell: for the title-word searches it was 1.93 to 3.14 ms in the shared table and 0.81 to 1.89 ms in the tenants' own tables.
Both designs returned the same number of matches for every one of the 599 word queries.
With eight clients searching at once for 30 seconds, each as a different tenant with 588 to 43,281 documents:
| Shared table | Table per tenant | |
|---|---|---|
| Answers per second | 2,691 | 8,765 |
| Median | 2.83 ms | 0.81 ms |
| 95th percentile | 4.16 ms | 1.33 ms |
| Slowest answer | 182.12 ms | 23.24 ms |
One measurement went the other way. Right after a restart, the first 200 searches in the largest tenant's own table took a median of 37.58 ms, with a 95th percentile of 187.78 ms, before they settled at 1.24 ms. In the shared table the first 200 took a median of 1.87 ms. The next section shows what removed this.
Memory, Files and Start Time per Table
After loading all 1,610,651 documents and restarting:
| Shared table | 99 tables | |
|---|---|---|
| Load time, four loading processes | 181.2 s | 90.0 s |
| Disk | 1.83 GiB | 2.16 GiB |
| Memory after restart | 72 MiB | 1.571 GiB |
| Time to stop | 5.3 s | 52.1 s |
| Time from start to the first answer | 3.3 s | 7.4 s |
Most of the 1.571 GiB is documents that were never written to a file. A table keeps new documents in memory until they reach rt_mem_limit, 128 MB by default, and only then writes them out. Most of the 99 tables are smaller than that. In a repeat of the load, the tables reported 1.46 GiB of documents held in memory.
FLUSH RAMCHUNK writes a table's in-memory documents to a file. The repeat compared three ways to keep the same 99 tables:
| 99 tables | Memory after restart | Median of a title search: small / median / largest tenant |
|---|---|---|
| As loaded | 1.572 GiB | 0.60 / 0.69 / 1.08 ms |
After FLUSH RAMCHUNK on every table | 223.4 MiB | 0.65 / 1.13 / 1.15 ms |
Created with rt_mem_limit='16M' | 906.4 MiB | 0.73 / 0.74 / 1.01 ms |
| The shared table in the same repeat | 59.4 MiB | 1.33 / 1.31 / 1.40 ms |
The flush cut the memory to a seventh, and the tenant tables were still faster than the shared one, though the median tenant's searches went from 0.69 to 1.13 ms. It also removed the slow first searches after a restart: in this repeat the largest tenant's first 200 took a median of 46.39 ms as loaded and 1.37 ms after the flush. The flush is not permanent. Documents written afterwards collect in memory again until the next flush or until the table reaches its limit.
To see what the number of tables alone costs, a second run gave every tenant 50 documents and raised the number of tenants. In the per-tenant design every tenant also got a user and two grants. The search in the last column is one common word, sent as a different tenant each time.
| Tenants, 50 documents each | Memory after restart | Files | Start to first answer | Search median |
|---|---|---|---|---|
| 100 tables | 121.6 MiB | 408 | 4.0 s | 0.49 ms |
| 1,000 tables | 977.6 MiB | 4,008 | 24.3 s | 0.67 ms |
| 2,500 tables | 2.386 GiB | 10,008 | 56.5 s | 0.52 ms |
| 3,530 tables | 3.362 GiB | 14,128 | 80.0 s | 0.62 ms |
| 100 tenants in one shared table | 34.3 MiB | 12 | 1.9 s | 0.55 ms |
| 1,000 tenants in one shared table | 27 MiB | 24 | 3.7 s | 0.98 ms |
| 10,000 tenants in one shared table | 35.5 MiB | 120 | 2.0 s | 0.98 ms |
Memory grew by about 1 MiB per table, and empty tables in a separate one-core test took about 1 MiB each as well. Search time did not depend on the number of tables. The run was meant to reach 10,000 tables. While tables were being created, memory use was higher than after a restart, and at 3,530 tables the server reached the 4 GB limit and the kernel killed it. It started again with all 3,530 tables and no table lost.
Creating a table with its user, two grants and 50 documents took 82 ms at the start and 175 ms near 2,500 tables. Adding a tenant to the shared table took about 10 ms.
The start time followed the number of users more than the number of tables. In a separate test with about 310 tables, the server answered its first authenticated query 2.7 s after start with 7 users, 14.5 s with 506, 31.7 s with 1,006 and about 45 s with 2,006. That test ran on one core. The time of a query did not change with the number of users.
The Noisy Neighbor Problem
The noisy neighbor problem is one tenant's load slowing down the others. To measure it, one client searched as the median tenant for 30 seconds, first alone, then while the largest tenant ran 16 clients with heavy searches (a common word with 1,000 results and a facet, and a phrase sorted by date), then while the largest tenant loaded all its documents again with four writers.
| Quiet tenant's search, median / 95th percentile | Shared table | Table per tenant |
|---|---|---|
| Alone | 1.24 / 1.84 ms | 0.75 / 1.07 ms |
| Largest tenant runs 16 heavy search clients | 29.32 / 43.51 ms | 15.02 / 22.84 ms |
| Largest tenant reloads its documents | 1.48 / 7.30 ms | 0.60 / 3.56 ms |
Heavy searches by one tenant slowed the quiet tenant 20 to 24 times in both designs. In the shared table one of its searches waited 12.3 seconds; with separate tables the slowest took 27 ms. The reload had a smaller effect: the median stayed within 0.25 ms of its value alone, and the 95th percentile rose 3 to 4 times.
A table per tenant gives a tenant its own files and its own memory. It does not give it its own share of the processor: all tables are served by the same four cores. If one tenant must not slow the others, the limit has to be set outside these two designs, for example as a rate limit per tenant in the application, or by putting the heaviest tenants on a separate server. Neither was measured here.
What a Tenant Filter Does Not Cover
Tenant isolation in the shared table rests on one condition, AND tenant_id=N. It limits the rows, COUNT(*), the total number of matches and the facets to one tenant. Three kinds of answers are built from the whole table.
Suggestions, Autocomplete and Keyword Statistics
The example at the end of this post has eight tenants. Its tables are created with min_infix_len='2', which suggestions and autocomplete need; the tables of the 99-tenant measurements were created without it. No document of the drones tenant contains the word stellar; the tenant built from the Stellar site uses it often. Searching the shared table as the drones tenant returns no rows, but the statistics of the search say where the word is:
SELECT id FROM posts WHERE MATCH('stellar') AND tenant_id=5;
SHOW META;
SHOW META reported the word in 1,755 documents, and so did CALL KEYWORDS('stellar', 'posts', 1 AS stats). The two calls behind "did you mean" and autocomplete behaved the same way:
CALL SUGGEST('stella', 'posts');
CALL AUTOCOMPLETE('stell', 'posts');
The first returned stella, stellar, stell, stellm and tell. The second returned ten completions, among them stellar, stellarsdk and stellarterm. In the drones tenant's own table the same calls reported the word in 0 documents, suggested tell, sell, tello, tells and shell, and offered no completion with stellar in it.
CALL KEYWORDS, CALL SUGGEST, CALL QSUGGEST and CALL AUTOCOMPLETE take a table name and no filter; adding one is rejected as an unknown option. They answer from the dictionary of the table, and in a shared table that dictionary holds the words of every tenant. A "did you mean" line or an autocomplete box built on them can show a word that exists only in another customer's documents, such as a product name or a person's name. SHOW META after a filtered search reports how many documents and occurrences each query word has in the whole table, so its numbers should not be passed on to a tenant either.
Ranking
The default ranking gives more weight to a word that is rare in the table. In the shared table "rare" is counted over all tenants, so the other tenants' documents change the order of results for this tenant.
Each tenant's 200 title searches were run in both designs and the first 20 results compared:
| Small tenant | Median tenant | Largest tenant | |
|---|---|---|---|
| Queries compared | 199 | 200 | 200 |
| Same number of matches | 199 | 200 | 200 |
| Same 20 documents | 194 | 167 | 129 |
| Same 20 documents in the same order | 161 | 103 | 77 |
The matches are the same; which of them come first is not. For the search tree still brown in the gardening tenant, the first result was the same document in both designs, and three of the next four were different documents.
A separate test with two tenants looked for a setting that removes the effect. The idf and local_df search options did not change the order. Rankers that do not use word rarity, such as wordcount, gave the same order in both designs.
A Database User per Tenant
In the per-tenant design every tenant has its own database user, allowed to read and write its own table and nothing else:
CREATE USER 'tenant_drones' IDENTIFIED BY '...';
GRANT read ON 'posts_drones' TO 'tenant_drones';
GRANT write ON 'posts_drones' TO 'tenant_drones';
This gives a second check on the application's own mistakes. Suppose a bug sends the drones tenant's request to another tenant's table while still using the drones user. In the shared design the same kind of bug, a missing or wrong tenant_id, returns the other tenant's rows without any error. Here Manticore answers HTTP 403:
{"error":"Permission denied for user 'tenant_drones'"}
The example sends ten such statements as tenant_drones. Seven name posts_stellar: a SELECT, an INSERT, an UPDATE, a DELETE, a DROP TABLE, an ALTER TABLE and an insert through the /bulk endpoint. One is a SELECT from the shared table, one is an ALTER TABLE on the user's own table, and the last repeats the first SELECT after a restart. All ten were refused, and the tables held the same rows afterwards.
The authorization reference
lists the permissions. The tenant users hold read and write and no schema, so they cannot create, alter or drop tables. In a separate test, write also allowed TRUNCATE, OPTIMIZE and FLUSH RAMCHUNK on the user's own table, and SHOW TABLES listed only the tables the user may read.
Two properties of grants matter when tenants come and go:
- A grant belongs to a table name, not to the table. After
GRANT read ON 'posts_reused' TO 'first_owner', the table was dropped and a new one created with the same name and other rows. The user could read the new rows without a new grant. Revoke before dropping a tenant's table, or a later table with that name is open to the old user. - A wildcard covers tables created later. After
GRANT read ON 'posts_*' TO 'reader_of_all', the user could read aposts_latercreated afterwards. A tenant's user should be granted exact table names.
What was tested is one statement sent to one table. That is the mistake an application makes when it routes a request wrongly. It was not tested as a barrier against someone who holds a tenant's credentials and writes their own statements, and the design does not need it to be one: as in the shared design, the credentials stay inside the application, and tenants never send SQL of their own.
If one user is granted all tenant tables, this check is gone, and the per-tenant design keeps only its other properties.
Users have a cost of their own. Creating 1,999 users with two grants each took 337.3 s in the one-core test, and the start time grew with the number of users, as shown above.
Document IDs in a Shared Table
A document id is unique in a table, and tenant_id is not part of it. If two tenants both have a document number 1 and the application uses that number as the id, the second INSERT fails:
{"error":"duplicate id '1'"}
REPLACE with the same id does not fail. It replaced tenant 1's document with tenant 2's. REPLACE has no place for a tenant condition: its partial form accepts only WHERE id=N.
So the shared table needs ids that cannot collide between tenants, and the tenant's own number goes into a separate column, post_id above. Two ways were tested:
- Build the id from both numbers. The measured shared table used
tenant_id * 100000000 + post_idfor all 1,610,651 documents. The multiplier has to be larger than any number a tenant will ever use. - Let Manticore assign the id. 1,004 inserts without an id got 1,004 different ids, such as
4399500327452147713.UPDATEandDELETEthen address a document asWHERE tenant_id=1 AND post_id=5, which left tenant 2's document number 5 unchanged. A full-text field cannot be changed byUPDATE, so replacing a document's text still needs its id.
With a table per tenant, both tenants can keep document 1. The tenant still has to travel with that number everywhere else in the application: in caches, in queues and in logs.
Schema Changes
Adding a column to the shared table is one statement for all tenants:
ALTER TABLE posts ADD COLUMN revision integer;
It took 0.63 s, and one search sent during it waited 630 ms. With separate tables the same statement ran once per table. The 97 tables left after the removal test of the next section took 47.19 s, a median of 430 ms each and 1.45 s for the slowest. A quiet tenant's searches went on during the loop with a median of 0.75 ms and one stall of 559 ms. No search failed in either design.
During those 47 seconds some tables had the new column and some did not. The application has to work with both shapes until the loop ends, and has to know which tables are done if the loop stops halfway.
Tenant Removal
Both removals took a fraction of a second for a tenant with 42,961 documents. What happened to the disk differs.
| Shared table | Table per tenant | |
|---|---|---|
| Statement | DELETE FROM posts WHERE tenant_id=N | REVOKE both grants, then DROP TABLE |
| Time | 0.051 s | 0.125 s |
| Rows gone from searches | at once | at once |
| Disk space | not freed | 53 MiB freed at once |
A second, small tenant of 1,787 documents was removed the same way. After the two DELETE statements the shared table still held 40,029 deleted documents in its files. They no longer appear in any search, but their text is on disk. A plain OPTIMIZE TABLE returned in half a second and removed none of them, because the table already had as few parts as the server aims for. Merging the table into one part did remove them:
OPTIMIZE TABLE posts OPTION sync=1, cutoff=1;
This took 224.1 s for the 1.8 GiB table and freed 54 MiB. Searches by another tenant kept a median of 1.25 ms during the merge, with one that took 458 ms. The compaction reference
describes OPTIMIZE and its options.
If a contract says a customer's data is erased when they leave, the shared design needs this merge as part of removal, and it rewrites every tenant's data. Backups and other copies were not part of the test in either design.
In both designs, stop the application from accepting the tenant's sessions and stop its loading jobs before removing the data, or a late write brings documents back.
Choosing a Design
| Shared table | Table per tenant | |
|---|---|---|
| Search time, word queries | 1.43 to 1.91 ms | 0.63 to 1.24 ms |
| Memory for 1.6 million documents | 72 MiB | 1.571 GiB as loaded, 223 MiB after FLUSH RAMCHUNK on every table |
| Number of tenants on 4 GB | 10,000 small tenants ran in 35 MiB | killed at 3,530 small tables, about 1 MiB each |
| A mistake in the application's tenant handling | a missing filter returns other tenants' rows | there is no filter to forget; a statement sent to the wrong table is refused when each tenant has its own user |
| Suggestions, autocomplete, keyword statistics | from all tenants' words | from the tenant's words |
| Ranking | depends on other tenants' documents | depends on the tenant's documents |
| A busy tenant | slows the others | slows the others |
| Adding a column | 0.63 s | 0.43 s per table, a loop to manage |
| Removing a tenant | fast; disk freed only by a full merge | fast; disk freed at once |
| Document ids | must be unique across tenants | each tenant keeps its own |
A shared table fits many small tenants with the same schema, where the application owns every query and no feature shows suggestions or statistics from the table. A table per tenant fits fewer, larger tenants, where memory for the tables is available, and where each tenant should get ranking and suggestions from its own documents.
The two can be combined: the many small tenants in one shared table, and the few large ones each in a table of their own. The numbers above describe both halves. The combination was not run as one system.
Limits
- One server. Replication and tables spread over several servers were not part of the run.
- Four cores and 4 GB on a shared host. The table count limit of 3,530 belongs to this memory size and to tables of 50 documents.
- Tenants of up to 43,281 documents. A tenant with millions of documents was not measured.
- Text search only. No vector search and no columnar storage.
- No limit on a tenant's load was tested, in Manticore or in front of it.
- Grants were tested with single statements that name one table, over HTTP with a user name and password. The MySQL protocol and access tokens were not.
- Removal was checked in the live tables only, not in backups or in the binary log.
- Timings are from one run each.
Running the Example
Download the example and its SHA-256 checksum . It builds both designs for eight tenants: 15,743 questions and answers from the eight smallest of the 99 sites. It needs Docker with the Compose plugin, Bash, and Python 3.8 or newer; only the standard library is used. We ran it on Linux only.
shasum -a 256 -c multi-tenant-search-isolation.zip.sha256
unzip multi-tenant-search-isolation.zip
cd tenant-search
./run.sh > run.log 2>&1
tail -1 run.log
The two reference runs took 24 and 23 seconds once the image was downloaded. A successful run ends with this line:
{"event": "PASS", "tenants": 8, "documents": 15743, "ranking_queries": 200, "ranking_queries_with_different_order": 7, "statements_refused_with_403": 10, "documents_of_removed_tenant": 2357}
check.py runs eight stages and stops at the first check that fails:
| Stage | What is checked | Result in the reference run |
|---|---|---|
| 1 | Both designs hold the same documents, written by their own database users | 15,743 documents, 9 users |
| 2 | A search with the tenant filter and without it | rows of 1 tenant with the filter, of 8 without |
| 3 | Keyword statistics, suggestions and autocomplete in the shared table | a word of another tenant is counted in 1,755 documents, suggested and completed |
| 4 | The same 200 queries for one tenant in both designs | same number of matches for all 200, different order for 7 |
| 5 | A tenant's database user names another tenant's table | 10 statements refused with HTTP 403 |
| 6 | Two tenants use the same document id in the shared table | the second INSERT is refused, REPLACE overwrites the first tenant's document |
| 7 | A column is added | one statement for the shared table, eight for the tenant tables |
| 8 | A tenant of 2,357 documents is removed | shared table: 12.9 MB of files before and after DELETE, 8.7 MB after the merge; own table: 1.7 MB gone with DROP TABLE |
./cleanup.sh removes the container and its data volumes.
The folder reference-evidence/ holds the records behind the numbers in this post: two complete runs of the example, the measurements on 99 tenants and the earlier single tests. The folder measure/ has the scripts for the 99-tenant measurements; they need a 1.97 GB download, about 6 GB of free disk and roughly an hour and a half. The sample documents are licensed CC BY-SA 4.0, and data/LICENSE.md says how to find the author of each one.

