Streamlined usage ingestion for SaaS billing systems.
Project details
MeterMesh serves as the essential layer for usage-based products, efficiently aggregating thousands of usage events into manageable data for your Postgres database. It handles traffic seamlessly, ensuring high availability and reliability, while simplifying the ingestion process without becoming an additional burden on your database.
MeterMesh is a robust solution designed for distributed usage ingestion tailored for SaaS billing applications. This tool efficiently processes usage events, consolidating them in memory for each customer on an hourly basis before writing the aggregated data into a Postgres database. MeterMesh serves as a high-performance intermediary that minimizes the number of writes to the database, effectively handling thousands of usage events without overwhelming the database.
MeterMesh operates on a simple architecture that integrates with a SaaS application as follows:
[SaaS app]
│
▼
[nginx LB :8080]
│
├─► node1 ──┐
├─► node2 ──┼─► Redis heartbeats (monitoring active nodes)
└─► node3 ──┘
│
│ owner totals hourly usage in RAM
▼
PostgreSQL customer_usage
MeterMesh offers a range of functionalities through its API:
| Method | Path | Purpose |
|---|---|---|
POST | /v1/usage | Accepts a usage event |
GET | /v1/totals | Retrieves in-memory totals for the node |
GET | /v1/stats | Provides counters for accepted, forwarded, and flushed events |
GET | /v1/route?customer_id= | Identifies the current owner of a customer's data |
GET | /v1/metrics/stream | Streams live metrics via Server-Sent Events |
POST | /v1/admin/exit | Initiates graceful shutdown for a node |
To track the usage of resources by your customers, a simple POST request can be made to the MeterMesh API as shown below:
POST /v1/usage
Content-Type: application/json
{"customer_id":"user_123","metric":"tokens","quantity":42}
This approach can be utilized at strategic points in your application, such as post successful API calls or at the conclusion of billable tasks.
MeterMesh stands out by providing not only efficient usage tracking but also ensuring that it remains lightweight and performant by minimizing unnecessary writes and handling node outages gracefully. While MeterMesh does not include features like invoicing or pricing logic, it serves as a critical component for collecting and managing usage data effectively for billing purposes.
Comments
0Start the conversation
Share the first comment.