Certainly! I'll create a comprehensive document that summarizes all the relevant information and context for this project. Here's the document:
We're developing a serverless system on Cloudflare to act as a Segment destination, process incoming events, and monitor for user-defined thresholds. The system will allow users to set complex criteria for monitoring their customer data and receive notifications when these criteria are met.
- The project originated from a need to find an alternative to tools like Pocus for creating materialized daily views of top moving customers based on Segment events.
- The system needs to handle composite metrics like number of users in a team, type of service, and monthly cost.
- It should provide webhook notifications when certain thresholds are met.
- The solution needs to be flexible and self-service, as existing vertical solutions were found insufficient.
- Cloudflare Workers for serverless computing
- Cloudflare Workers Analytics Engine for data storage and querying
- Cloudflare Workers KV for storing user-defined thresholds
- Next.js for the frontend user interface
- Receives events from Segment
- Processes and stores events in Workers Analytics Engine
- Creates composite indexes for efficient querying
- Allows users to create, read, update, and delete threshold configurations
- Stores configurations in Workers KV
- Runs periodically to check if any thresholds have been crossed
- Queries Workers Analytics Engine based on user-defined thresholds
- Sends webhook notifications when thresholds are crossed
- Provides a dashboard for users to manage their threshold configurations
- Allows viewing, creating, and editing of thresholds
- Composite indexing of event data
- User-defined thresholds with complex criteria
- Flexible query language for defining thresholds
- Real-time or near-real-time event processing
- Scalable, serverless architecture
Events are stored with a composite index combining multiple fields:
const compositeIndex = `${event.userId}:${event.teamSize}:${event.serviceType}:${event.monthlyCost}`;
Thresholds are defined using a JSON structure:
{
"conditions": [
{ "field": "teamSize", "operator": ">", "value": 10 },
{ "field": "monthlyCost", "operator": ">=", "value": 1000 }
],
"aggregation": {
"field": "value",
"function": "sum",
"timeWindow": "7d"
},
"triggerValue": 5000
}
- ThresholdList: Displays all existing thresholds
- ThresholdForm: Allows creation and editing of thresholds
- Implement the Segment destination Worker
- Develop the threshold management and checking Workers
- Create API routes for the Next.js frontend
- Build out the user interface components
- Implement error handling and validation
- Add visualizations for threshold proximity
- Test the system with real Segment event data
This document provides a comprehensive overview of the project, its components, and the next steps for implementation. It should allow you to pick up where we left off and continue development of the Segment Event Threshold Monitoring System.
Here is some dummy data that can be used for the chart:
{
"data": [
{ "date": "2023-01-01", "value": 1500 },
{ "date": "2023-01-02", "value": 1800 },
{ "date": "2023-01-03", "value": 2100 },
{ "date": "2023-01-04", "value": 2400 },
{ "date": "2023-01-05", "value": 2700 },
{ "date": "2023-01-06", "value": 3000 },
{ "date": "2023-01-07", "value": 3300 }
]
}