Develop a data dictionary linking user events, backend entities, and feature store…
- User
Develop a data dictionary linking user events, backend entities, and feature store columns.
Assistant
Develop a data dictionary linking user events, backend entities, and feature store columns.
1. Understand the Goal: The user wants a "data dictionary" that links three specific layers of a data system: * User Events (raw interactions, frontend logs). * Backend Entities (database tables, core business objects). * Feature Store Columns (derived, ML-ready features).
Identify the Scenario/Domain: A generic "data dictionary" is too abstract to be useful. I need to pick a concrete domain to make the example understandable and realistic. An E-commerce or Ride-sharing app are the standard "Hello World" examples for data engineering. Let's go with an E-commerce/Retail scenario because the user events (clicks, purchases) map intuitively to entities (users, products) and features (propensity to buy, lifetime value).
Structure the Output: A good technical document needs structure.
Drafting the Content - Layer by Layer:
Scenario: Online Store ("ShopNow").
Layer 1: User Events (The "What happened?")
add_to_cart: User clicks button.page_view: User looks at a product.purchase_success: Transaction completes.search_query: User types "red shoes".Layer 2: Backend Entities (The "What is it?")
users: ID, email, created_at.products: SKU, category, price.transactions: Order ID, amount, status.user_interactions (often a mirror of events in the DB).Layer 3: Feature Store (The "What does it mean for ML?")
user_lifetime_value, days_since_last_purchase, avg_cart_size.product_popularity_score, return_rate.is_weekend, time_to_purchase.Creating the Linkage (The "Data Dictionary"):
I need to show how Event A + Entity B becomes Feature C.
Example 1: Customer Loyalty
purchase_successtransactions table joined with users table.user_30_day_spend (Aggregation of transaction amounts for a user over 30 days).Example 2: Product Interest
view_productproducts table.product_view_count_7d (Count of view events per SKU).Refining the Format: Instead of just a list, I will create a schema that looks like a specification document.
Adding Value - "The Pipeline Context": A data dictionary doesn't exist in a vacuum. I should briefly mention the flow: Event -> Ingestion -> Raw Data -> Transformation -> Feature Store -> Model.
Review against User Request:
Self-Correction/Polish:
Final Output Generation: (This matches the provided good response).
user_id, product_id.(Self-Correction during drafting the response): Make sure to distinguish between streaming features (real-time events) and batch features (historical entities). I will add a "Compute Mode" column to the dictionary to add professional depth.
Final Polish: Check formatting (Markdown tables, code blocks). Ensure clear headings.
(Self-Correction Example during drafting): I initially forgot to mention PII. Action: Added a "PII/Sensitivity" flag to the metadata definition to show security awareness.
Below is a structured Data Dictionary framework. It maps the journey from a raw user action (Clickstream) to the database record (Backend) and finally to the derived value used by Machine Learning models (Feature Store).
user_purchase_propensity (Likelihood a user buys in the next 24 hours).user_id, product_id, event_timestamp.This dictionary is organized by Feature Groups. Each entry traces the lineage from the Source Event Backend Entity Feature Store Column.
Focus: How the user interacts with the app/site.
| Feature Store Column Name | Data Type | Description (Feature Logic) | Source Event (Raw) | Backend Entity (SQL Table) | Transformation Logic (ETL) |
|---|---|---|---|---|---|
user_7d_click_count | INT | Number of distinct clicks by the user in the last 7 days. | click_event | raw_events.web_clickstream | COUNT(event_name) WHERE event_name = 'click' OVER (PARTITION BY user_id ORDER BY timestamp ROWS BETWEEN 7d PRECEDING AND CURRENT ROW) |
user_avg_session_duration | FLOAT | Average time spent per session (in minutes). | session_start, session_end | dw.user_sessions | AVG(session_end_time - session_start_time) grouped by user_id. |
user_days_since_last_login | INT | Recency of user activity. Used as a proxy for churn risk. | login_success | core.users | DATEDIFF(CURRENT_DATE, MAX(login_timestamp)). |
most_viewed_category_30d | STRING | The product category the user views most often. | view_product | raw_events.product_views | MODE() OVER (PARTITION BY user_id) on product_category for last 30 days. |
Focus: Historical purchasing habits and financial value.
| Feature Store Column Name | Data Type | Description (Feature Logic) | Source Event (Raw) | Backend Entity (SQL Table) | Transformation Logic (ETL) |
|---|---|---|---|---|---|
user_lifetime_value (LTV) | FLOAT | Total gross revenue generated by the user. | purchase_success | finance.transactions | SUM(transaction_amount) WHERE status = 'success'. |
user_chargeback_rate | FLOAT | Percentage of transactions resulting in chargebacks. | dispute_created | risk.fraud_cases | COUNT(disputes) / COUNT(transactions). |
avg_transaction_size_90d | FLOAT | Average order value in last 3 months. | checkout_complete | sales.orders | AVG(order_total) filtered for last 90 days. |
discount_usage_ratio | FLOAT | Ratio of orders using promo codes. | apply_promo | sales.order_discounts | COUNT(order_id WITH promo_code) / COUNT(total_order_id). |
Focus: Characteristics of the items being interacted with.
| Feature Store Column Name | Data Type | Description (Feature Logic) | Source Event (Raw) | Backend Entity (SQL Table) | Transformation Logic (ETL) |
|---|---|---|---|---|---|
product_current_price | FLOAT | Live price of the product. | price_change (Event) | inventory.products | Direct map from products.price. Updated on price change events. |
product_stock_status | INT (0/1) | Binary flag if item is in stock. | inventory_update | inventory.stock_levels | CASE WHEN stock_qty > 0 THEN 1 ELSE 0 END. |
product_category_vector | ARRAY[FLOAT] | Embedding vector representing product category. | product_upload | ml.product_embeddings | Pre-computed embedding (BERT/Word2Vec) on category_name. |
To fully implement this, you need the underlying schemas.
Captured by the Frontend/SDK.
{
"event_name": "purchase_success",
"event_id": "uuid-v4",
"user_id": "user-123",
"device_id": "cookie-id-456",
"timestamp": "2023-10-27T10:00:00Z",
"context": {
"product_id": "prod-999",
"cart_value": 54.20,
"currency": "USD"
}
}
Stored in the Data Warehouse or Operational DB.
-- Table: finance.transactions
CREATE TABLE transactions (
transaction_id VARCHAR(36) PRIMARY KEY,
user_id VARCHAR(36),
amount DECIMAL(10, 2),
status ENUM('pending', 'success', 'failed'),
created_at TIMESTAMP,
updated_at TIMESTAMP
);
The final serving layer for models.
| column_name | type | description |
|---|---|---|
user_id | STRING | Entity Key. Unique identifier for the user. |
feature_timestamp | TIMESTAMP | Event Time. Time the feature calculation is valid for. |
user_7d_click_count | INT | Pre-computed feature from Group A. |
user_lifetime_value | FLOAT | Pre-computed feature from Group B. |
label_purchased | BOOL | Target Label. Did they purchase? (Used for training). |
Entity Resolution:
device_id (cookies) before login, and user_id after login.device_id to user_id so features calculated from anonymous browsing can be attributed to the logged-in user in the Feature Store.Point-in-Time Correctness:
Event with the Feature state exactly as it existed at Event Timestamp - T.Aggregation Windows: