Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions docs/how-to-guides/online-server-performance-tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ When the server processes a `get_online_features()` call, it groups the requeste
**DynamoDB exception:** DynamoDB stores each feature view in its own table and overrides `_read_features_per_fv()` to pack the keys of every feature view into **shared `BatchGetItem` requests**, since one request can read from several tables. A request touching any number of feature views costs as few as **1** request (up to `batch_size` keys per request, sent in parallel) on both the sync and async paths. As with PostgreSQL, requests larger than `max_batched_result_rows` (entity rows × feature views, default 2048) read one view at a time, single-view requests are never batched, and `max_batched_result_rows: 0` turns batching off.

**Bigtable exception:** Bigtable keeps every feature view keyed on the same entities in one shared table, with rows keyed `{entity_id}#{feature_view_name}`, and overrides `_read_features_per_fv()` to fetch the rows of all those views with **one `ReadRows` call per table**. A request touching any number of feature views on the same entities costs **1** call; views on different entity sets cost one call per entity set. This applies to the sync path, which is the only read path Bigtable has. As with PostgreSQL and DynamoDB, requests larger than `max_batched_result_rows` (entity rows × feature views, default 2048) read one view at a time, single-view requests are never batched, and `max_batched_result_rows: 0` turns batching off. The call's row filter selects, for the rows of each view, only the features requested from that view. A request whose filter would come close to Bigtable's 20 KB row filter limit also reads one view at a time.

**MongoDB exception:** MongoDB stores every feature view of an entity in the same document and overrides `_read_features_per_fv()` to read all requested feature views with a **single `find`** over the entity ids of every view, projecting only the features requested from each view. A request touching any number of feature views costs **1** query on both the sync and async paths. As with PostgreSQL, DynamoDB and Bigtable, requests larger than `max_batched_result_rows` (entity rows × feature views, default 2048) read one view at a time, single-view requests are never batched, and `max_batched_result_rows: 0` turns batching off.
{% endhint %}

### Feature services are free (and can be faster)
Expand Down Expand Up @@ -93,7 +95,7 @@ Requesting just `combined_score` triggers reads from **both** `driver_stats_fv`

## Pre-computed feature vectors

When a `get_online_features()` request touches multiple feature views, the server issues a separate store read per feature view. For services spanning 5–15+ feature views, this fan-out dominates latency — even where the store batches its reads (Redis, PostgreSQL, DynamoDB), the protobuf deserialization and response-building overhead grows linearly with the number of views.
When a `get_online_features()` request touches multiple feature views, the server issues a separate store read per feature view. For services spanning 5–15+ feature views, this fan-out dominates latency — even where the store batches its reads (Redis, PostgreSQL, DynamoDB, Bigtable, MongoDB), the protobuf deserialization and response-building overhead grows linearly with the number of views.

**Pre-computed feature vectors** solve this by storing all of a feature service's features for each entity as a single serialized blob. At read time, the server fetches one blob per entity instead of N reads per feature view, reducing the operation to O(1).

Expand Down Expand Up @@ -289,7 +291,7 @@ The online store is the single largest factor in `get_online_features()` latency
| **Redis / Dragonfly** | < 1 ms | No (threadpool) | Ultra-low latency, high throughput; all FV reads batched into 1 pipeline | Requires in-memory capacity for your dataset |
| **DynamoDB** | 2–5 ms | Yes | Serverless, auto-scaling on AWS; FV reads packed into shared batch requests | Pay-per-request cost; batch API limits (100 items) |
| **PostgreSQL** | 3–10 ms | No (threadpool) | Teams with existing Postgres infra; all FV reads batched into 1 query | Connection pooling needed at scale |
| **MongoDB** | 2–5 ms | Yes | Flexible schema, async-native | Requires index tuning for large datasets |
| **MongoDB** | 2–5 ms | Yes | Flexible schema, async-native; all FV reads batched into 1 query | Requires index tuning for large datasets |
| **Aerospike** | < 1 ms | No (threadpool) | Ultra-low latency, hybrid memory (RAM + SSD), large datasets | Namespace must be pre-configured on the cluster |
| **Bigtable** | 3–8 ms | No (threadpool) | Large-scale GCP workloads; FV reads on the same entities batched into 1 `ReadRows` call | Row-key design affects read performance |
| **Cassandra / ScyllaDB** | 2–5 ms | No (threadpool) | Multi-region, write-heavy | Tunable consistency; requires DC-aware routing |
Expand All @@ -315,7 +317,7 @@ The feature server can read from the online store using either an **async** or *
| Store | Async read | Async write | Notes |
| ----- | ---------- | ----------- | ----- |
| **DynamoDB** | Yes | Yes | Uses `aiobotocore` for non-blocking I/O. `_read_features_per_fv` is overridden to pack all feature view reads into shared `BatchGetItem` requests |
| **MongoDB** | Yes | Yes | Uses `motor` (async MongoDB driver) |
| **MongoDB** | Yes | Yes | Uses PyMongo's native `AsyncMongoClient`. `_read_features_per_fv` is overridden to batch all feature view reads into a single `find` |
| **PostgreSQL** | Implemented | No | Has `online_read_async` but does not yet advertise via `async_supported`; uses sync/threadpool path. `_read_features_per_fv` is overridden to batch all feature view reads into a single `UNION ALL` query |
| **Redis** | Implemented | **Yes** | `online_read_async` and `online_write_batch_async` both implemented; uses sync/threadpool path for `get_online_features` (`_read_features_per_fv` overridden with batched single pipeline) |
| **Aerospike** | Implemented | No | Async methods wrap the blocking C client via `run_in_executor`; does not yet advertise via `async_supported`, so the server still uses the threadpool path |
Expand Down Expand Up @@ -465,7 +467,7 @@ online_store:

### MongoDB tuning

MongoDB supports async reads natively. Use `client_kwargs` to pass performance options directly to the PyMongo / Motor driver:
MongoDB supports async reads natively. Use `client_kwargs` to pass performance options directly to the PyMongo driver:

```yaml
online_store:
Expand All @@ -482,7 +484,8 @@ online_store:

- **`maxPoolSize` / `minPoolSize`**: Controls the driver connection pool. Default `maxPoolSize` is 100 in PyMongo, but explicitly setting it ensures predictability across versions.
- **`connectTimeoutMS` / `socketTimeoutMS`**: Tighter timeouts improve p99 by failing fast on slow connections.
- MongoDB is one of the stores with **full async support** (read and write), so it benefits from concurrent feature view reads via `asyncio.gather()`.
- **`max_batched_result_rows`**: Requests spanning several feature views read every view with a single `find`, up to this many entity rows × feature views (default 2048). Set to `0` to read one feature view at a time.
- MongoDB is one of the stores with **full async support** (read and write), so the feature server reads it without a thread pool.

### Aerospike tuning

Expand Down
13 changes: 13 additions & 0 deletions docs/reference/online-stores/mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ Both sync and async methods are fully supported:
* `online_read` / `online_read_async`
* `online_write_batch` / `online_write_batch_async`

## Batched Multi-Feature-View Reads

Every feature view of an entity is stored in the same document. When a request spans several feature views, they are all read with a single `find` over the entity ids of every view, which projects only the event timestamp and the features requested from each view. A request for 10 feature views therefore costs **1** query instead of 10, on both the sync and async read paths. Requests larger than `max_batched_result_rows` (entity rows × feature views, default 2048) read one feature view at a time instead, because the single query holds the features of every view at once and its peak memory grows with the number of views. A single-view request is never batched. Set `max_batched_result_rows: 0` to turn batching off.

{% code title="feature_store.yaml" %}
```yaml
online_store:
type: mongodb
connection_string: "mongodb://localhost:27017"
max_batched_result_rows: 2048 # set to 0 to read one feature view at a time
```
{% endcode %}

## Functionality Matrix

The set of functionality supported by online stores is described in detail [here](overview.md#functionality).
Expand Down
Loading
Loading