Skip to content

TablesDB benchmarks: up to 73% faster bulk writes

We benchmarked the database layer behind TablesDB on PostgreSQL, MariaDB, and MongoDB. Bulk writes are up to 73% faster and nested creates take half the time.

8 min read

Joins and aggregations just arrived in TablesDB, and they needed more than new query methods. They shipped with a new major version of the database layer under TablesDB, the open-source utopia-php/database library. That layer doesn't only run the new queries. It runs every listRows(), createRows(), and deleteRows() call your app already makes, including in apps that will never use a join. So we benchmarked it before and after the upgrade.

Setting up the benchmark

We wanted a like-for-like answer: the same actions, on the same machine, against the same engines, with only the version of the database layer changing. A faster version only counts if it is faster at the work apps already do, and if it returns the same answers. So we ran 74 existing actions on both versions, checked that both returned identical results for every one, and measured the new joins and aggregations on their own.

The actions we measured

The actions cover the work TablesDB does for apps every day, plus the new queries:

  • List queries. 7 actions, including rows filtered on a column, sorted, and limited to a page, and reads that select a subset of columns. These are the reads behind almost every screen of an app.
  • Bulk writes. Creating, updating, and deleting 1,000 rows in one call, and upserting 100. The sizes match the bulk operation limits on Appwrite Cloud: up to 1,000 rows per request on the Pro plan and 100 on the Free plan.
  • Relationships. 27 actions on rows with related rows, including creating a row with one-to-many related rows two levels deep and listing rows with many-to-many related rows two levels deep.
  • Long filters. Equal filters on lists of 1,000 and 5,000 IDs, to show how each version copes as a query grows.
  • Joins and aggregations. The new queries, measured on their own, since version 7 can't run them.

The benchmarking system

  • Hardware. A dedicated 8-vCPU droplet, running PHP 8.5.8 with Swoole 6.2.2 and opcache.
  • Engines. PostgreSQL 16, MariaDB 10.11, and MongoDB 8.0, the three engines a self-hosted Appwrite instance can run on, plus MySQL 8.0.43 and 8.0.41. This post reports the first three. MySQL followed the same pattern and had the largest single gain of the run: filters on 5,000 IDs were 28 times faster.
  • Rounds. Each action ran in 3 to 9 interleaved rounds, alternating which version ran first.
  • Table layouts. Every action ran against plain tables and against shared tables, where many projects share one set of tables, as on Appwrite Cloud.
  • Numbers. Times are p50 (median) latencies. Each percentage is the median per-round change across both table layouts, so it can differ by a few points from the ratio of the two times next to it.
  • Code. Most of the changes between the two versions landed in utopia-php/database#823, if you want to read the code behind the numbers.

The benchmark measures the database layer directly. It doesn't include HTTP, authentication, or response encoding, which an Appwrite API request adds on top. Requests that spend most of their time in the database, such as bulk writes, see the largest share of these gains.

Running the benchmark

Here is what changed in each group of actions, and the code changes behind each result.

Bulk writes take up to 73% less time

ActionPostgreSQLMariaDBMongoDB
Delete 1,000 rows175 → 47.6 ms (−73%)201 → 70.9 ms (−65%)231 → 101 ms (−57%)
Update 1,000 rows243 → 96.5 ms (−60%)231 → 79.9 ms (−66%)290 → 148 ms (−49%)
Create 1,000 rows350 → 188 ms (−46%)320 → 148 ms (−54%)332 → 174 ms (−49%)
Upsert 100 rows42.9 → 24.6 ms (−43%)42.8 → 23.1 ms (−46%)111 → 93.4 ms (−18%)

Version 7 did part of the work of a bulk write once per row. Version 8 does it once per call:

  • Cache invalidation. Version 7 purged the cached copy of every row a bulk write touched, with two cache calls per row. Appwrite runs the database layer with a Redis cache, so a 1,000-row write made 2,000 cache calls on top of its queries. Version 8 retires the table's cached rows once per call.
  • Validation. A bulk create built a new structure validator for every row. Version 8 builds one per call and reuses it.
  • Metadata. A bulk write reads the table's definition at most once per call instead of once per page of rows.
  • Permissions. A bulk update that changes permissions read the current permissions of each row in a separate query. Version 8 reads them for every row in one query.

These are the calls behind data imports, syncs from other systems, and cleanup jobs in functions: createRows(), updateRows(), upsertRows(), and deleteRows().

Nested creates take half the time and under a third of the round trips

Relationships let you create a row and its related rows in one call, by nesting the related rows in the data. The benchmark creates a row with a one-to-many relationship two levels deep. On version 7.4.1 that took 81 round trips to the database. On version 8.3.10 it takes 23, on every engine, and the create takes 48% to 53% less time.

The round trips explain the time. Version 7 handled each nested row on its own: it read the row to check whether it already existed, created it, and read it back. Version 8 checks whether any of the new related rows exist with one lookup per related table, then writes them all without reading any of them first or reading them back. When one of the nested rows already exists, version 8 relates them one by one as before, so the gain applies to creates where the related rows are new.

Reads with relationships improved too. Listing 25 rows with many-to-many related rows two levels deep is 39% faster on PostgreSQL and MariaDB and 27% faster on MongoDB. Across all 27 relationship actions in the benchmark, the median action is 24% to 31% faster.

Everyday list queries are about 20% faster

The benchmark's list actions are the reads an app makes on almost every screen: rows filtered on a column, sorted, and limited to a page. They got faster without any change to the queries.

ActionPostgreSQLMariaDBMongoDB
Equal filter, ordered, 25 rows1.62 → 1.35 ms (−18%)1.51 → 1.15 ms (−25%)3.02 → 1.79 ms (−39%)
Select a subset of columns1.43 → 1.17 ms (−20%)1.41 → 1.07 ms (−27%)1.90 → 1.45 ms (−23%)
Median of 7 list actions−19%−20%−21%

No single change accounts for this. Version 7 built a new query validator on every list call. Version 8 uses a lighter validator for plain queries, or reuses one per table, and does less work when it decodes and casts the values of each row it returns.

A few hundred microseconds to just over a millisecond per query is small on its own. It adds up on a page that makes several queries, and on a server that handles many of them at once.

Long ID lists stopped being slow on SQL engines

An equal filter on a list of IDs is how you fetch a known set of rows in one query. On the SQL engines, version 7.4.1 got slow as the list grew. With 5,000 IDs, PostgreSQL took 127 ms and MariaDB 405 ms. Version 8.3.10 takes 10.0 ms and 35.6 ms. MongoDB already handled long ID lists well and didn't change.

The cause was how the filter reached the database. Version 7 turned an equal filter on 5,000 values into 5,000 separate comparisons joined with OR, each with its own placeholder. Version 8 sends the same values as one IN (...) list. MongoDB's adapter already used MongoDB's $in operator, which is why its time didn't change.

A TablesDB query accepts up to 500 values, so your app never sends 5,000 IDs in one filter. The benchmark didn't measure 500, but the gain shrinks with the list: with 1,000 IDs, MariaDB went from 38.8 ms to 7.79 ms, about 5 times faster instead of 11. Expect a smaller gain than the chart shows for the lists your app sends. Lists of a few hundred IDs also make long URLs, and createQuery() takes the same queries in the request body.

Joins and aggregations run in tens of milliseconds

Joins and aggregations didn't exist in version 7, so there's no before. Instead, the benchmark measures them on a 50,000-row table with permissions enforced, where the caller can read 10% of the rows, joined to tables of 10,000 rows each. These are p50 times over 3 rounds on plain tables.

QueryPostgreSQLMariaDB
Inner join, 1 table13 ms13 ms
Inner join chain, 4 tables28 ms27 ms
Inner join chain, 8 tables91 ms44 ms
Left join, 1 table3.6 ms13 ms
Join with selected columns37 ms20 ms
Group by 1 column, with count22 ms25 ms
Group by with having23 ms25 ms
Group by 2 columns23 ms25 ms
Distinct values22 ms23 ms

Both run inside the database. A join is a SQL JOIN, and aggregations use SQL aggregate functions with GROUP BY and HAVING, so rows aren't sent to Appwrite to be matched or counted. Permissions are part of the same query: each joined table gets the same permission check a direct read of it would, and these times include that check.

Most queries took about as long on PostgreSQL as on MariaDB. The exceptions go both ways: PostgreSQL was faster on a left join to one table (3.6 ms against 13 ms), and MariaDB was faster on the eight-join chain (44 ms against 91 ms) and on a join with selected columns (20 ms against 37 ms).

Compare these times with what they replace. A join replaces a second request and the code that matches its results to the first. An aggregation replaces downloading every matching row to count or add them up in your app. The announcement post shows both in every SDK.

TablesDB doesn't offer joins and aggregations on MongoDB, and the benchmark didn't measure them there.

Summary of the TablesDB benchmark results

  • Every engine got faster. Across 74 measured actions, the median action is 19% faster on PostgreSQL and MongoDB and 16% faster on MariaDB.
  • Bulk writes of 1,000 rows take up to 73% less time. Deletes are 57% to 73% faster, updates 49% to 66%, and creates 46% to 54%.
  • Nested creates take half the time. Creating a row with two levels of related rows takes 48% to 53% less time, and needs 23 database round trips instead of 81.
  • Everyday reads are about 20% faster. A filtered, ordered list of 25 rows is 18% to 39% faster.
  • Long ID lists stopped being slow on SQL. In the database layer, filtering on 5,000 IDs is 13 times faster on PostgreSQL and 11 times faster on MariaDB. Apps send at most 500 values per query, and the gain shrinks with the list.
  • Joins and aggregations run in tens of milliseconds. One join on a 50,000-row table took 13 ms at the median, with permissions enforced.

Get the faster TablesDB on Appwrite Cloud or self-hosted 2.6

On Appwrite Cloud, TablesDB already runs on the new database layer, and there is nothing to change.

Self-hosted instances get it by upgrading to Appwrite 2.6.0 or later. Appwrite 2.6.0 ships version 8.3.12 of the database layer, two patch releases after the 8.3.10 build the benchmark measured. Neither patch is a performance change.

Your queries don't change. The same SDK calls run on the faster code. Start with the calls this benchmark measured:

On PostgreSQL, MariaDB, and MongoDB, the median of 74 benchmarked actions is 16% to 19% faster, depending on the engine. Bulk writes of 1,000 rows are 46% to 73% faster, creating a row with two levels of related rows takes about half the time, and common list queries are about 20% faster.

No. The gains come from the database layer under TablesDB, so the same listRows(), createRows(), updateRows(), upsertRows(), and deleteRows() calls run faster. On Appwrite Cloud there is nothing to do. Self-hosted instances get it by upgrading to Appwrite 2.6.0 or later.

PostgreSQL 16, MariaDB 10.11, and MongoDB 8.0, which are the engines a self-hosted Appwrite instance can run on, plus MySQL 8.0. Every engine got faster. Joins and aggregations were measured on the SQL engines only, because they aren't available on MongoDB.

On a 50,000-row table with permissions enforced, a join to one 10,000-row table took 13 ms at the median on PostgreSQL and MariaDB. A chain of four joins took 27 to 28 ms, and grouping with a count took 22 to 25 ms. See Joins and Aggregations.

No. They measure the database layer directly, on one server, without HTTP, authentication, or response encoding. An API request adds that work on top, so the end-to-end gain for a request is smaller than the database gain, and larger for requests that spend most of their time in the database, such as bulk writes.

Version 8 of the database layer does work once per call that version 7 did once per row. It retires the table's cached rows once instead of purging each row's cache entry, builds one structure validator for a bulk create instead of one per row, and reads the table's definition once per call instead of once per page of rows. See Bulk operations.

Read next