Replacing existing TURN servers
If you are a existing TURN provider but would like to switch to providing Cloudflare Calls TURN for your customers, there is a few considerations.
Cloudflare Calls TURN service can reduce tangible and untangible costs associated with TURN servers:
- Server costs (AWS EC2 etc)
- Bandwidth costs (Egress, load balancing etc)
- Time and effort to set up a TURN process and maintenance of server
- Scaling the servers up and down
- Maintain the TURN server with security and feature updates
- Maintain high availability
When using Cloudflare Calls TURN service at scale, consider separating environments such as "testing", "staging" or "production" with TURN keys. You can create up to 1,000 TURN keys in your account, which can be used to generate end user credentials.
There is no limit to how many end-user credentials you can create with a particular TURN key.
Cloudflare Calls TURN service lets you tag each credential with a custom identifier as you generate a credential like below:
Use this field to aggregate usage for a specific user or group of users and collect analytics.
You can monitor account wide usage with the GraphQL analytics API. This is useful for keeping track of overall usage for billing purposes, watching for unexpected changes. You can get timeseries data from TURN analytics with various filters in place.
If you share TURN credentials with end users, credential abuse is possible. You can monitor for abuse by tagging each credential with custom identifiers and monitoring for top custom identifiers in your application via the GraphQL analytics API.
When billing for TURN usage in your application, it's crucial to understand and account for adaptive sampling in TURN analytics. This system employs adaptive sampling to efficiently handle large datasets while maintaining accuracy.
The sampling process in TURN analytics works on two levels:
- At data collection: Usage data points may be sampled if they are generated too quickly.
- At query time: Additional sampling may occur if the query is too complex or covers a large time range.
To ensure accurate billing, write a single query that sums TURN usage per customer per time period, returning a single value. Avoid using queries that list usage for multiple customers simultaneously.
By following these guidelines and understanding how TURN analytics handles sampling, you can ensure more accurate billing for your end users based on their TURN usage.
Below is a query that queries usage only for a single customer.