---
title: "Define features and push velocity data"
description: "Create a fraud feature repository with PushSource, run feast apply, and push a velocity snapshot."
---

# Define features and push velocity data

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

On this page, you define a push-backed feature view, register it with `feast apply`, and push one velocity snapshot to confirm the write path. The [Aerospike online store reference](https://github.com/feast-dev/feast/blob/master/docs/reference/online-stores/aerospike.md) and [Feast push source reference](https://docs.feast.dev/reference/data-sources/push) cover the full configuration options.

## Create the feature repository

Create the project directory, feature store configuration, and the push-backed feature view definition.

1.  Create a project directory:
    
    Terminal window
    
    ```shell
    mkdir -p fraud-feast-demo/data
    
    cd fraud-feast-demo
    ```
    
2.  Create `feature_store.yaml`:
    
    feature\_store.yaml
    
    ```yaml
    project: fraud_detection
    
    registry: data/registry.db
    
    provider: local
    
    online_store:
    
      type: aerospike
    
      hosts:
    
        - ["127.0.0.1", 3000]
    
      namespace: test
    
      ttl_seconds: 600
    
      read_timeout_ms: 150
    
      write_timeout_ms: 300
    
    entity_key_serialization_version: 3
    
    offline_store:
    
      type: file
    ```
    
    `registry: data/registry.db` is Feast’s local metadata store for entity and feature view definitions. `offline_store: type: file` is required by Feast even in push-only demos. Feast validates its presence but does not use it for reading in this tutorial. `ttl_seconds: 600` covers a five-minute velocity window plus buffer. `provider: local`, `entity_key_serialization_version: 3`, and the `hosts` list format are explained in [Tutorial: Serve real-time Feast features with Aerospike](https://aerospike.com/docs/develop/feast-aerospike-online-store/step/3/part/0/define-and-materialize#create-the-feature-repository) on the Define and materialize page.
    
3.  Create `fraud_repo.py`:
    
    fraud\_repo.py
    
    ```python
    from datetime import timedelta
    
    from feast import Entity, FeatureService, FeatureView, Field, FileSource, PushSource
    
    from feast.types import Float64, Int64
    
    from feast.value_type import ValueType
    
    account = Entity(
    
        name="account",
    
        join_keys=["account_id"],
    
        value_type=ValueType.STRING,
    
        description="Bank or wallet account identifier",
    
    )
    
    txn_velocity_batch = FileSource(
    
        path="data/txn_velocity.parquet",
    
        timestamp_field="event_timestamp",
    
    )
    
    txn_velocity_push = PushSource(
    
        name="txn_velocity_push",
    
        batch_source=txn_velocity_batch,
    
    )
    
    txn_velocity_fv = FeatureView(
    
        name="txn_velocity_5m",
    
        entities=[account],
    
        ttl=timedelta(minutes=10),
    
        schema=[
    
            Field(name="txn_count_5m", dtype=Int64),
    
            Field(name="amount_sum_5m", dtype=Float64),
    
            Field(name="distinct_merchants_5m", dtype=Int64),
    
        ],
    
        online=True,
    
        source=txn_velocity_push,
    
        tags={"domain": "fraud", "window": "5m"},  # Descriptive only. Feast routing does not use tags.
    
    )
    
    fraud_scoring_service = FeatureService(
    
        name="fraud_scoring_v1",
    
        features=[txn_velocity_fv],
    
        description="Velocity features for real-time fraud scoring",
    
    )
    ```
    
    `PushSource` allows `batch_source` to be omitted, but this tutorial defines features through `FeatureView`. Feast’s `FeatureView` constructor requires a `batch_source` on every stream source, including `PushSource`, so `txn_velocity_batch` is included here. That `FileSource` registers schema for `feast apply` and is not used when you write through `store.push()` at runtime. The Parquet file it references does not need to exist at apply time.
    
    `txn_velocity_push` is the source name you pass to `store.push()`. `txn_velocity_5m` is the feature view name Feast uses in the registry and feature references.
    
    `online=True` marks the feature view as eligible for online serving. It is the default value for `FeatureView`. Setting `online=False` restricts the view to offline retrieval and prevents `get_online_features` from reading it.
    
    `ttl=timedelta(minutes=10)` controls Feast materialization lookback and historical point-in-time retrieval. It does not make the standard Aerospike online read reject an old value. `ttl_seconds: 600` in `feature_store.yaml` is the serving-layer control: Aerospike expires the record ten minutes after its latest write.
    
    `FeatureService` wraps the feature view under a named service. Your request references `fraud_scoring_v1` rather than enumerating individual features. Coordinate service-membership changes with the model’s expected schema and version the service when its contract changes.
    
4.  Register definitions:
    
    `feast apply` reads the Python definitions in your project directory and records them in the Feast registry at `data/registry.db`. From that point, commands and SDK calls know your entity, feature view, and feature service by name. It registers definitions only. It does not move any feature values.
    
    Terminal window
    
    ```shell
    feast apply
    ```
    
    Expected result
    
    ```text
    No project found in the repository. Using project name fraud_detection defined in feature_store.yaml
    
    Applying changes for project fraud_detection
    
    Deploying infrastructure for txn_velocity_5m
    ```
    
5.  Confirm registration:
    
    -   Output includes `Applying changes for project fraud_detection`.
    -   Output includes `Deploying infrastructure for txn_velocity_5m`.

## Push a velocity snapshot

Write a velocity snapshot into the Aerospike online store with `store.push()` and read it back to confirm the write and read paths work end to end. The values you push here stand in for the output of a real aggregation job.

1.  Create `push_velocity.py`:
    
    push\_velocity.py
    
    ```python
    from datetime import datetime, timezone
    
    import pandas as pd
    
    from feast import FeatureStore
    
    from feast.data_source import PushMode
    
    store = FeatureStore(repo_path=".")
    
    snapshot = pd.DataFrame(
    
        {
    
            "account_id": ["acct-1001"],
    
            "event_timestamp": [datetime.now(timezone.utc)],
    
            "txn_count_5m": [7],
    
            "amount_sum_5m": [1243.50],
    
            "distinct_merchants_5m": [3],
    
        }
    
    )
    
    store.push("txn_velocity_push", snapshot, to=PushMode.ONLINE)
    
    print("Pushed velocity snapshot for acct-1001")
    ```
    
    `FeatureStore(repo_path=".")` loads the registry from `feature_store.yaml` in the current directory.
    
    `store.push()` takes a pandas `DataFrame`. It must include the entity join key (`account_id`), `event_timestamp`, and one `DataFrame` column for every feature field defined in `txn_velocity_5m`, with column names matching the `Field` names exactly.
    
    `event_timestamp` records when the velocity snapshot was computed, here set to the current system time. Production scoring code or monitoring can inspect that timestamp to enforce a stricter freshness limit than the record TTL.
    
    The first argument to `store.push()` is the `PushSource` name (`txn_velocity_push`), not the feature view name. Feast routes the pushed values to the right feature view through the source name.
    
    `PushMode.ONLINE` writes only to the Aerospike online store. `PushMode.ONLINE_AND_OFFLINE` also requires a writable batch source for offline history, as explained on the [Wrap up](https://aerospike.com/docs/develop/feast-aerospike-fraud-velocity/step/4/part/0/wrap-up) page.
    
2.  Run it:
    
    Terminal window
    
    ```shell
    python3 push_velocity.py
    ```
    
    Expected result
    
    ```plaintext
    Pushed velocity snapshot for acct-1001
    ```
    
3.  Confirm the push:
    
    -   The script prints `Pushed velocity snapshot for acct-1001` without errors.
    -   `PushMode.ONLINE` wrote only to the Aerospike online store.

On the next page, you read features through the `FeatureService` and optional HTTP feature server.

::: undefined
-   I’ve created the fraud feature repository.
-   I’ve run `feast apply` and pushed a velocity snapshot with `store.push()`.
:::

[Previous  
Push sources and velocity features](https://aerospike.com/docs/develop/feast-aerospike-fraud-velocity/step/2/part/0/push-and-velocity) [Next  
Serve features to a fraud model](https://aerospike.com/docs/develop/feast-aerospike-fraud-velocity/step/3/part/1/serve-features)