Build and deploy a recommendation system with FeatureStore for end-to-end feature management.
Architecture overview
FeatureStore manages features throughout their lifecycle and connects Alibaba Cloud services through Python, Go, C++, and Java SDKs:
| Layer | Role | Services |
|---|---|---|
| Data | Store offline features and serve online | MaxCompute (offline), FeatureDB / Hologres / Tablestore (online) |
| Feature management | Organize features into projects, entities, and views | FeatureStore console or Python SDK |
| Training | Export a training set by joining features with labels | EasyRec framework |
| Serving | Synchronize features, host models, orchestrate recommendations | DataWorks (scheduling), EAS (model service, C++ SDK), PAI-REC (Go SDK) |
For a code walkthrough, run the Python Notebook in DSW Gallery.
For background, read the FeatureStore overview.
For questions, join DingTalk group 34415007523.
Prerequisites
Complete the following setup:
| Required product | Action |
|---|---|
| Platform for AI (PAI) | Activate PAI and create a PAI workspace. Activate PAI and create a default workspace. |
| MaxCompute | 1. Activate MaxCompute. 2. Create a MaxCompute project. |
| FeatureDB | Activate FeatureDB. Create a new online data source: FeatureDB. Follow on-screen prompts. |
| DataWorks | 1. Activate DataWorks and create a workspace. Create a workspace. 2. Purchase an exclusive resource group for scheduling and attach it to the workspace. Use an exclusive resource group for scheduling. 3. Configure a MaxCompute data source for the PAI workspace. Configure a data source. 4. Attach a MaxCompute compute engine to the PAI workspace. Attach a MaxCompute engine. 5. Attach a Hologres compute engine to the PAI workspace. Attach a Hologres compute engine. |
| Object Storage Service (OSS) | Activate OSS. Quick Start in the console. |
Step 1: Prepare data
Sync data tables
A typical recommendation scenario requires three data tables: user features, item features, and labels. This tutorial uses simulated tables in the pai_online_project MaxCompute project.
| Table | Name | Entries per partition | Size |
|---|---|---|---|
| User | rec_sln_demo_user_table_preprocess_all_feature_v1 |
~100,000 | ~70 MB |
| Item | rec_sln_demo_item_table_preprocess_all_feature_v1 |
~100,000 | ~70 MB |
| Label | rec_sln_demo_label_table |
~450,000 | ~5 MB |
Run the following SQL in DataWorks to sync these tables from pai_online_project to your MaxCompute project.
Create an ODPS SQL node
-
Log on to the DataWorks console.
-
In the navigation pane on the left, click Data Development and O&M > Data Development.
-
Select the DataWorks workspace you created and click Go to Data Studio.
-
Hover over Create, and choose Create Node > MaxCompute > ODPS SQL. Configure the node parameters.
Parameter Suggested value Node Type ODPS SQL Path Business Flow/Workflow/MaxCompute Name Enter a custom name. -
Click OK.
Run the sync SQL commands
In the node area, run the following SQL for each table. For Resource Group, select the exclusive resource group for scheduling you created.
Sync the user table: rec_sln_demo_user_table_preprocess_all_feature_v1 (Click to view details)
Sync the item table: rec_sln_demo_item_table_preprocess_all_feature_v1 (Click to view details)
Sync the label table: rec_sln_demo_label_table (Click to view details)
For all three tables, ${bdp.system.bizdate} must resolve to these partition dates:
-
ds=20231022
-
ds=20231023
-
ds=20231024
Populate all three partitions using the data backfill procedure in the next section.
Perform data backfill
-
In the DataWorks console, in the navigation pane, click Data Development & O&M > Operation Center. Select the workspace from the drop-down list and click Enter Operation Center.
-
In the navigation pane, click Auto Triggered Task O&M > Auto Triggered Task.
-
In the list of auto triggered tasks, click the target task to view its directed acyclic graph (DAG).
-
Right-click the target node and choose Data Backfill > Current Node. Select a data backfill mode.
-
Set Data Timestamp to a range from 2023-10-22 to 2023-10-24 and click Submit.
Verify sync
Confirm these tables exist in your MaxCompute project with partitions for ds=20231022, ds=20231023, and ds=20231024:
-
rec_sln_demo_user_table_preprocess_all_feature_v1 -
rec_sln_demo_item_table_preprocess_all_feature_v1 -
rec_sln_demo_label_table
Configure data sources
FeatureStore requires an offline store (MaxCompute) and an online store (FeatureDB, Hologres, or Tablestore). This tutorial uses MaxCompute and FeatureDB.
-
Log on to the PAI console. In the navigation pane, click Data Preparation > FeatureStore.
-
Select a workspace and click Enter FeatureStore.
-
Configure the MaxCompute data source. On the Data Source tab, click Create Store. Set the following parameters.
Parameter Suggested value Type MaxCompute Name Enter a custom name. MaxCompute Project Name Select the MaxCompute project you created. -
Configure the FeatureDB data source. If you already created one, skip this step. On the Store tab, click Create Store. Set the following parameters. Click Submit.
Parameter Suggested value Type FeatureDB (If first use, follow on-screen prompts to activate) Name Cannot be customized. Default value is feature_db. Username Set a username. Password Set a password. VPC high-speed connection (Optional) After successful configuration, use the FeatureStore SDK in a VPC to access FeatureDB through PrivateLink. This reduces latency and improves performance. VPC Select the VPC where your online FeatureStore service is located. Zone and vSwitch Select a zone and vSwitch. Select the vSwitch for the zone where your online service machine is located. Select vSwitches in at least two zones for high availability.
Install the FeatureStore Python SDK
Install the SDK on the DataWorks exclusive resource group for scheduling.
-
Log on to the DataWorks console.
-
In the navigation pane on the left, click Resource Group.
-
On the Exclusive Resource Groups tab, find the resource group where Purpose is set to Data Scheduling. Click the
icon for the schedule resource and choose O&M Assistant. -
Click Create Command. Set the following parameters.
Parameter Suggested value Command Name Enter a custom name. This tutorial uses install. Command Type Manual Input (pip Command Cannot Be Used To Install Third-party Packages) Command Content /home/tops/bin/pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple https://feature-store-py.oss-cn-beijing.aliyuncs.com/package/feature_store_py-2.0.2-py3-none-any.whlTimeout Enter a custom time. -
Click OK to create the command.
-
Click Command. In the page that appears, click Running.
-
Click the
button to view the latest execution status. When the status changes to Successful, the installation is complete.
Step 2: Create and register a FeatureStore project
Create and register a FeatureStore project using the console or SDK. Install the Python SDK regardless of method — later steps require it for training set export and data sync.
Method 1: Use the console
Create a project
-
Log on to the PAI console. In the navigation pane on the left, click Data Preparation > FeatureStore.
-
Select a workspace and click Enter FeatureStore.
-
On the Project tab, click Create Project. Set the following parameters.
Parameter Suggested value Name Enter a custom name. This tutorial uses fs_demo. Description Enter a custom description. Offline Store Select the MaxCompute data source you created. Online Store Select the FeatureDB data source you created. -
Click Submit.
Create feature entities
-
On the Projects page of FeatureStore, click the project name to view project details.
-
On the Feature Entity tab, click Create Feature Entity. Set the parameters for the user entity.
Parameter Suggested value Feature Entity Name Enter a custom name. This tutorial uses user. Join Id user_id -
Click Submit.
-
Click Create Feature Entity. Set the parameters for the item entity.
Parameter Suggested value Feature Entity Name Enter a custom name. This tutorial uses item. Join Id item_id -
Click Submit.
Create feature views
-
On the project details page, on the Feature View tab, click Create Feature View. Set the parameters for the user feature view.
Parameter Suggested value View Name Enter a custom name. This tutorial uses user_table_preprocess_all_feature_v1. Type Offline Write Mode Use Offline Table Store Select the MaxCompute data source that you created. Feature Table Select the user table you prepared, rec_sln_demo_user_table_preprocess_all_feature_v1. Feature Field Select the user_id primary key. Synchronize Online Feature Table Yes Feature Entity user Feature Lifecycle Keep the default value. -
Click Submit.
-
Click Create Feature View. Set the parameters for the item feature view.
Parameter Suggested value View Name Enter a custom name. This tutorial uses item_table_preprocess_all_feature_v1. Type Offline Write Method Use Offline Table Store Select the MaxCompute data source that you created. Feature Table Select the item table you prepared, rec_sln_demo_item_table_preprocess_all_feature_v1. Feature Field Select the item_id primary key. Synchronize Online Feature Table Yes Feature Entity item Feature Lifecycle Keep the default value. -
Click Submit.
Create a label table
-
On the project details page, on the Label Tables tab, click Create Label Table. Set the following parameters.
Parameter Suggested value Store Select the MaxCompute data source that you created. Table Name Select the label table you prepared, rec_sln_demo_label_table. -
Click Submit.
Create a model feature
-
On the project details page, on the Model Features tab, click Create Model Feature. Set the following parameters.
Parameter Suggested value Model Feature Name Enter a custom name. This tutorial uses fs_rank_v1. Select Feature Select the user feature view and item feature view you created. Label Table Name Select the label table you created, rec_sln_demo_label_table. -
Click OK.
-
On the model feature list page, click Details in the row of the model you created.
-
On the Basic Information tab of the Model Feature Details page, view Export Table Name. The name is fs_demo_fs_rank_v1_trainning_set. Use this table for feature generation and model training.
The table name fs_demo_fs_rank_v1_trainning_set contains "trainning" (double n). This matches the system-generated table name. Use this exact spelling in all references.
Install SDK
Install the FeatureStore Python SDK if you have not done so.
Method 2: Use Python SDK
For SDK usage steps, see DSW Gallery.
Step 3: Export the training set and train the model
Export the training set
-
Log on to the DataWorks console.
-
In the navigation pane on the left, click Data Development & O&M > Data Development.
-
Select the DataWorks workspace that you created and click Go to Data Studio.
-
Hover over Create, and choose Create Node > MaxCompute > PyODPS 3. Set the following parameters.
Parameter Suggested value Engine Instance Select the MaxCompute engine you created. Node Type PyODPS 3 Path Business Flow/Workflow/MaxCompute Name Enter a custom name. -
Click Confirm.
-
Copy the following script into the node.
from feature_store_py.fs_client import FeatureStoreClient
from feature_store_py.fs_project import FeatureStoreProject
from feature_store_py.fs_datasource import LabelInput, MaxComputeDataSource, TrainingSetOutput
from feature_store_py.fs_features import FeatureSelector
from feature_store_py.fs_config import LabelInputConfig, PartitionConfig, FeatureViewConfig
from feature_store_py.fs_config import TrainSetOutputConfig, EASDeployConfig
import datetime
import sys
from odps.accounts import StsAccount
cur_day = args['dt']
print('cur_day = ', cur_day)
offset = datetime.timedelta(days=-1)
pre_day = (datetime.datetime.strptime(cur_day, "%Y%m%d") + offset).strftime('%Y%m%d')
print('pre_day = ', pre_day)
access_key_id = o.account.access_id
access_key_secret = o.account.secret_access_key
sts_token = None
endpoint = 'paifeaturestore-vpc.cn-beijing.aliyuncs.com'
if isinstance(o.account, StsAccount):
sts_token = o.account.sts_token
fs = FeatureStoreClient(access_key_id=access_key_id, access_key_secret=access_key_secret, security_token=sts_token, endpoint=endpoint)
cur_project_name = 'fs_demo'
project = fs.get_project(cur_project_name)
label_partitions = PartitionConfig(name = 'ds', value = cur_day)
label_input_config = LabelInputConfig(partition_config=label_partitions)
user_partitions = PartitionConfig(name = 'ds', value = pre_day)
feature_view_user_config = FeatureViewConfig(name = 'user_table_preprocess_all_feature_v1',
partition_config=user_partitions)
item_partitions = PartitionConfig(name = 'ds', value = pre_day)
feature_view_item_config = FeatureViewConfig(name = 'item_table_preprocess_all_feature_v1',
partition_config=item_partitions)
feature_view_config_list = [feature_view_user_config, feature_view_item_config]
train_set_partitions = PartitionConfig(name = 'ds', value = cur_day)
train_set_output_config = TrainSetOutputConfig(partition_config=train_set_partitions)
model_name = 'fs_rank_v1'
cur_model = project.get_model(model_name)
task = cur_model.export_train_set(label_input_config, feature_view_config_list, train_set_output_config)
task.wait()
print("task_summary = ", task.task_summary)
-
In the right-side pane, click Scheduling Configuration. Set the following parameters.
Parameter Suggested value Scheduling Parameters Parameter Name dt Parameter Value $[yyyymmdd-1] Resource Properties Scheduling Resource Group Select the exclusive resource group for scheduling that you created. Scheduling Dependencies Select the user table and item table you created. -
After configuring and testing the node, save and submit the node configuration.
View export task (optional)
-
On the FeatureStore Projects page, click a project name to open its details page.
-
On the Feature Entity tab, click Jobs.
-
Click Details in the row of the target task to view its basic information, run configuration, and task logs.
Train the model
EasyRec is an open-source recommendation framework that integrates with FeatureStore to train, export, and publish models. Use the fs_demo_fs_rank_v1_trainning_set table as input to train a model with EasyRec.
| Resource | Link |
|---|---|
| EasyRec source code | EasyRec on GitHub |
| EasyRec documentation | EasyRec Introduction |
| EasyRec training guide | EasyRec Training |
For EasyRec questions, join PAI consultation group on DingTalk (Group ID: 32260796).
Step 4: Deploy the model
Deploy the trained model. FeatureStore provides Python, Go, C++, and Java SDKs for custom recommendation systems. Contact DingTalk group 32260796 for integration support.
This section demonstrates deployment with Alibaba Cloud services.
Schedule data synchronization
Schedule regular synchronization of user and item feature tables from the offline store to the online store.
-
Log on to the DataWorks console.
-
In the navigation pane on the left, click Data Development & O&M > Data Development.
-
Select the DataWorks workspace that you created and click Go to Data Studio.
-
Schedule synchronization for user_table_preprocess_all_feature_v1 (Click to view details)
-
Schedule synchronization for item_table_preprocess_all_feature_v1 (Click to view details)
Verify
After synchronization, verify in Hologres that features were written to the online store.
Create and deploy EAS model service
EasyRec Processor includes the FeatureStore C++ SDK for low-latency, high-performance feature retrieval. It receives scoring requests from the recommendation engine, fetches features, runs inference, and returns scores.
-
Log on to the DataWorks console.
-
In the navigation pane on the left, click Data Development & O&M > Data Development.
-
Select the DataWorks workspace that you created and click Go to Data Studio.
-
Hover over New, and choose New Node > MaxCompute > PyODPS 3.
-
Copy the following script.
import os
import json
config = {
"name": "fs_demo_v1",
"metadata": {
"cpu": 4,
"rpc.max_queue_size": 256,
"rpc.enable_jemalloc": 1,
"gateway": "default",
"memory": 16000
},
"model_path": f"oss://beijing0009/EasyRec/deploy/rec_sln_demo_dbmtl_v1/{args['ymd']}/export/final_with_fg", # Path of the trained model. customize the path.
"model_config": {
"access_key_id": f'{o.account.access_id}',
"access_key_secret": f'{o.account.secret_access_key}',
"region": "cn-beijing", # Replace this with the region where PAI is deployed. This tutorial uses cn-beijing as an example.
"fs_project": "fs_demo", # Replace this with the name of your FeatureStore project. This tutorial uses fs_demo as an example.
"fs_model": "fs_rank_v1", # Replace this with the name of your FeatureStore model feature. This tutorial uses fs_rank_v1 as an example.
"fs_entity": "item",
"load_feature_from_offlinestore": True,
"steady_mode": True,
"period": 2880,
"outputs": "probs_is_click,y_ln_playtime,probs_is_praise",
"fg_mode": "tf"
},
"processor": "easyrec-1.9",
"processor_type": "cpp"
}
with open("echo.json", "w") as output_file:
json.dump(config, output_file)
# Run the following line for the first deployment
os.system(f"/home/admin/usertools/tools/eascmd -i {o.account.access_id} -k {o.account.secret_access_key} -e pai-eas.cn-beijing.aliyuncs.com create echo.json")
# Run the following line for scheduled updates
# os.system(f"/home/admin/usertools/tools/eascmd -i {o.account.access_id} -k {o.account.secret_access_key} -e pai-eas.cn-beijing.aliyuncs.com modify fs_demo_v1 -s echo.json")
-
In the right-side pane, click Scheduling Configuration. Set the following parameters.
Parameter Suggested value Scheduling Parameters Parameter Name dt Parameter Value $[yyyymmdd-1] Resource Properties Scheduling Resource Group Select the exclusive resource group for scheduling you created. Scheduling Dependencies Select the corresponding training task and item_table_preprocess_all_feature_v1. -
After configuring and testing the node, run it and check deployment status.
-
After deployment completes, comment out line 34, uncomment line 37, and submit the task for scheduled execution. > Tip: Line 34 uses
createfor first-time deployment. Line 37 usesmodifyfor subsequent scheduled updates. After initial deployment succeeds, switch to themodifycommand. -
(Optional) View the deployed service on the Inference Service tab of the Elastic Algorithm Service (EAS) page. Custom deployment.
-
(Optional) If your data source requires VPC access (such as Hologres), connect the EAS and data source VPCs. For Hologres:
-
Find VPC ID and vSwitch ID on the Network Information page of the Hologres instance.
-
On the EAS service page, click Configure High-Speed Connection in the upper-right corner.
-
Enter the corresponding VPC ID and vSwitch ID.
-
Enter a Security Group Name. Select an existing security group or create one. Hologres typically uses port 80. The security group must allow traffic on this port.
-
Click OK. The service becomes available after the update completes.
-
Configure PAI-REC
PAI-REC is a recommendation engine service that integrates the FeatureStore Go SDK. It connects with FeatureStore and EAS.
Configure FeatureStoreConfs
Set RegionId to the region where your product is located. This tutorial uses cn-beijing. Set ProjectName to the FeatureStore project you created (fs_demo).
"FeatureStoreConfs": {
"pairec-fs": {
"RegionId": "cn-beijing",
"AccessId": "${AccessKey}",
"AccessKey": "${AccessSecret}",
"ProjectName": "fs_demo"
}
},
Configure FeatureConfs
These parameters control how PAI-REC fetches features:
| Parameter | Value | Description |
|---|---|---|
FeatureStoreName |
pairec-fs |
Must match the key in FeatureStoreConfs. |
FeatureStoreModelName |
fs_rank_v1 |
Model feature name you created. |
FeatureStoreEntityName |
user |
Instructs Go SDK to fetch features from the user entity. |
"FeatureConfs": {
"recreation_rec": {
"AsynLoadFeature": true,
"FeatureLoadConfs": [
{
"FeatureDaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "pairec-fs",
"FeatureKey": "user:uid",
"FeatureStoreModelName": "fs_rank_v1",
"FeatureStoreEntityName": "user",
"FeatureStore": "user"
}
}
]
}
},
Configure AlgoConfs
This configuration specifies which EAS model scoring service PAI-REC connects to.
| Parameter | Description |
|---|---|
Name |
Must match deployed EAS service name. |
Url and Auth |
Obtain URL and token by clicking the service name on the EAS model service page. Then, on the Overview tab, in the Basic Information section, click View Endpoint Information. See EAS FAQ. |
"AlgoConfs": [
{
"Name": "fs_demo_v1",
"Type": "EAS",
"EasConf": {
"Processor": "EasyRec",
"Timeout": 300,
"ResponseFuncName": "easyrecMutValResponseFunc",
"Url": "eas_url_xxx",
"EndpointType": "DIRECT",
"Auth": "eas_token"
}
}
],
Troubleshooting
| Symptom | Possible cause | Solution |
|---|---|---|
| Data backfill task fails | Incorrect partition dates or missing source data | Verify ${bdp.system.bizdate} resolves to 20231022, 20231023, or 20231024. Check that pai_online_project source tables are accessible. |
| FeatureStore SDK installation fails | Network connectivity issues on the exclusive resource group | Check network connectivity. Verify the pip install URL is reachable from the resource group. |
| Feature sync to online store fails | Incorrect data source configuration or missing permissions | Verify MaxCompute and FeatureDB data source configurations. Confirm AccessKey has read and write permissions on both stores. |
| EAS deployment fails | Incorrect model path or insufficient EAS resources | Verify OSS model path. Check the EAS endpoint (pai-eas.cn-beijing.aliyuncs.com) is correct for your region. |
| EAS service cannot access Hologres | VPC network not connected or security group blocks port 80 | Configure a high-speed connection between EAS and Hologres VPC. Ensure the security group allows traffic on port 80. |