-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement "accounting" service that tracks user egress and updates Stripe #137
Comments
Hey @travis and @alanshaw, In order to implement the Accounting Service that tracks egress traffic, we will establish a system with the following components:
graph TD;
A[Freeway Cloudflare Worker] -->|Push Egress Events| B[SQS Queue];
B -->|Trigger| C[AWS Lambda Function];
C -->|Store Event| D[DynamoDB Table];
C -->|Record Usage| E[Stripe API];
subgraph AWS
B
C
D
end
subgraph External
A
E
end
style A fill:#f9f,stroke:#333,stroke-width:2px;
style B fill:#bbf,stroke:#333,stroke-width:2px;
style C fill:#bbf,stroke:#333,stroke-width:2px;
style D fill:#bbf,stroke:#333,stroke-width:2px;
style E fill:#f9f,stroke:#333,stroke-width:2px;
|
This looks great to me! The one thing it's missing is a discussion of operational monitoring - I think we need, at minimum, monitoring and alerting on the SQS queue to make sure we know when the reader (a lambda I assume?) is falling behind. We definitely also want alerting on any errors coming out of this system - this is probably as simple as making sure Sentry is configured for each of the components, but worth noting. Before you start implementation could you create issues (probably sub-issues of this one - should be as simple as creating a "todo" list with new issues - see https://dev.to/keracudmore/create-sub-issues-in-github-issues-409m for more detail) for each of these tasks? We'll make sure to get them into the sprint starting this week. |
Sounds great! Thanks for reviewing it. I just updated the ticket description with the tasks. |
Final Architecture: Egress Traffic Tracking and Stripe Billing Meters API IntegrationAn asynchronous solution for tracking egress traffic in the Freeway Gateway and reporting events to Stripe’s Billing Meters API. RFC ReferenceStoracha Network is implementing a scalable, automated mechanism for tracking egress traffic and updating Stripe’s API with relevant data to ensure accurate customer billing. This RFC outlines the proposed approaches and their trade-offs. ImplementationThe selected approach for this implementation is Alternative 3: Flow
graph TD
CF[Freeway Gateway] --> w3infra[w3infra/upload-api]
w3infra --> Kinesis[Kinesis Stream]
Kinesis --> EgressRecord[Space Content Handler]
EgressRecord --> SQS[Egress Traffic Queue]
SQS --> Lambda[Lambda Function]
Lambda --> DynamoDB[Egress Traffic DynamoDB Table]
Lambda --> Stripe[Stripe Billing Meters API]
EgressRecord --> Logs[S3 Bucket /Receipts]
Key Advantages
|
This is done and deployed to Staging. |
When requests come into the gateway, the last thing they do will be to send a UCAN invocation (? should it be a UCAN invocation?) to a new "egress accounting service" that will record important metadata about the request and record the usage in our Stripe account.
While this seems like it might make sense as an AWS-based lambda service, I think it's also worth seriously considering writing this as a Cloudflare worker, since the rest of the read pipeline is in Cloudflare. If we go this route, we should consider alternatives to the AWS UCAN stream and will need to figure out how to connect to Stripe from Cloudflare apps (this should not be hard).
The accounting service may also be expected to update caches or datastores based on the invocations it receives.
This service will record usage in Stripe, but should also keep enough information about accounting to support our billing and product development processes.
Tasks for Egress Event Tracking and Billing Integration
The text was updated successfully, but these errors were encountered: