Skip to content
Merged
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
124 changes: 123 additions & 1 deletion docs/reference/online-stores/remote.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Description

This remote online store will let you interact with remote feature server. At this moment this only supports the read operation. You can use this online store and able retrieve online features `store.get_online_features` from remote feature server.
This remote online store lets you interact with a remote feature server. You can use this online store to retrieve online features via `store.get_online_features()` from a remote feature server.

## Examples

Expand All @@ -25,6 +25,128 @@ auth:

`cert` is an optional configuration to the public certificate path when the online server starts in TLS(SSL) mode. This may be needed if the online server is started with a self-signed certificate, typically this file ends with `*.crt`, `*.cer`, or `*.pem`.

## Connection Pooling Configuration

The remote online store uses HTTP connection pooling to improve performance by reusing TCP/TLS connections across multiple requests. This significantly reduces latency by avoiding the overhead of establishing new connections for each request.

### Configuration Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `connection_pool_size` | int | 50 | Maximum number of connections to keep in the pool. Increase for high-concurrency workloads. |
| `connection_idle_timeout` | int | 300 | Maximum time in seconds a session can be idle before being closed. Set to `0` to disable idle timeout. |
| `connection_retries` | int | 3 | Number of retries for failed requests with exponential backoff. |

### Example with Connection Pooling

{% code title="feature_store.yaml" %}
```yaml
project: my-local-project
registry: /remote/data/registry.db
provider: local
online_store:
type: remote
path: http://feast-feature-server:80

# Connection pooling configuration (optional)
connection_pool_size: 50 # Max connections in pool
connection_idle_timeout: 300 # Idle timeout in seconds (0 to disable)
connection_retries: 3 # Retry count with exponential backoff

entity_key_serialization_version: 3
auth:
type: no_auth
```
{% endcode %}

### Use Cases

**High-throughput workloads:**
```yaml
online_store:
type: remote
path: http://feast-server:80
connection_pool_size: 100 # More connections for high concurrency
connection_idle_timeout: 600 # 10 minutes idle timeout
connection_retries: 5 # More retries for resilience
```

**Long-running services:**
```yaml
online_store:
type: remote
path: http://feast-server:80
connection_idle_timeout: 0 # Never auto-close session
```

**Resource-constrained environments:**
```yaml
online_store:
type: remote
path: http://feast-server:80
connection_pool_size: 10 # Fewer connections to reduce memory
connection_idle_timeout: 60 # 1 minute timeout
```

### Performance Benefits

Connection pooling provides significant latency improvements:

- **Without pooling**: Each request requires a new TCP connection (~10-50ms) and TLS handshake (~30-100ms)
- **With pooling**: Subsequent requests reuse existing connections, eliminating connection overhead

This is especially beneficial for:
- High-frequency feature retrieval in real-time inference pipelines
- Batch processing with many sequential `get_online_features()` calls
- Services with authentication enabled (reduces token refresh overhead)

### Session Cleanup

The HTTP session is automatically managed with idle timeout, but you can also explicitly close it when your application is shutting down or when you want to release resources.

#### Using FeatureStore context manager (recommended)

The recommended way to ensure proper cleanup is to use the `FeatureStore` as a context manager:

```python
from feast import FeatureStore

# Session is automatically closed when exiting the context
with FeatureStore(repo_path=".") as store:
features = store.get_online_features(
features=["driver_hourly_stats:conv_rate"],
entity_rows=[{"driver_id": 1001}]
)
```

#### Explicit cleanup

You can also explicitly close the session by calling `close()` on the `FeatureStore`:

```python
from feast import FeatureStore

store = FeatureStore(repo_path=".")
try:
features = store.get_online_features(
features=["driver_hourly_stats:conv_rate"],
entity_rows=[{"driver_id": 1001}]
)
finally:
store.close() # Closes HTTP session and releases resources
```

#### Direct session management

For advanced use cases, you can directly manage the HTTP session via `HttpSessionManager`:

```python
from feast.permissions.client.http_auth_requests_wrapper import HttpSessionManager

# Close the cached HTTP session
HttpSessionManager.close_session()
```

## How to configure Authentication and Authorization
Please refer the [page](./../../../docs/getting-started/concepts/permission.md) for more details on how to configure authentication and authorization.

27 changes: 27 additions & 0 deletions sdk/python/feast/infra/online_stores/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from feast import Entity, FeatureView, RepoConfig
from feast.infra.online_stores.helpers import _to_naive_utc
from feast.infra.online_stores.online_store import OnlineStore
from feast.permissions.client.http_auth_requests_wrapper import HttpSessionManager
from feast.protos.feast.types.EntityKey_pb2 import EntityKey as EntityKeyProto
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
from feast.repo_config import FeastConfigBaseModel
Expand Down Expand Up @@ -51,6 +52,18 @@ class RemoteOnlineStoreConfig(FeastConfigBaseModel):
""" str: Path to the public certificate when the online server starts in TLS(SSL) mode. This may be needed if the online server started with a self-signed certificate, typically this file ends with `*.crt`, `*.cer`, or `*.pem`.
If type is 'remote', then this configuration is needed to connect to remote online server in TLS mode. """

# Connection pooling configuration
connection_pool_size: int = 50
""" int: Maximum number of connections to keep in the pool (default 50).
Increase for high-concurrency workloads. """

connection_idle_timeout: int = 300
""" int: Maximum time in seconds a session can be idle before being closed (default 300 = 5 minutes).
Set to 0 to disable idle timeout. """

connection_retries: int = 3
""" int: Number of retries for failed requests with exponential backoff (default 3). """


class RemoteOnlineStore(OnlineStore):
"""
Expand Down Expand Up @@ -544,6 +557,20 @@ def teardown(
):
pass

async def close(self) -> None:
"""
Close the HTTP session and release connection pool resources.

This method is called automatically when FeatureStore.close() is invoked.
It cleans up the cached HTTP session used for connection pooling.

Note: Since the session is shared globally, calling close() will affect
all RemoteOnlineStore instances in the same process. This is typically
fine for SDK usage where there's usually one FeatureStore per process.
"""
HttpSessionManager.close_session()
logger.debug("RemoteOnlineStore HTTP session closed")


@rest_error_handling_decorator
def get_remote_online_features(
Expand Down
Loading
Loading