来自服务器缓存的 Mixpanel 跟踪
Mixpanel tracking from server caching
这是一道一般性的设计题。我目前正在将跟踪事件从我的服务器(C# web api 托管在 azure 上)发送到 Mixpanel(使用 Mixpanel.NET 包:https://github.com/chrisnicola/Mixpanel.NET)。
这在大多数情况下工作正常。但是,它并不像我希望的那样健壮:
1. 虽然很小,但它不必要地减慢了我的服务器速度,因为事件是在 API 的正常使用期间发送的。
2.如果mixpanel宕机,事件丢失
解决这些问题的最佳方法是什么?我在想我可以在我的服务器上缓存事件并最终将它们发送到 Mixpanel。这是一个好方法吗?猜测我需要使用某种类型的持久存储以防我的服务器在发送之前出现故障。 Azure 队列对此有好处吗?
提前致谢。
- 根据消息的大小,您可以将它们写入 Azure Storage Queue or Azure Service Bus. If your message is too large to go on the queue on its own you could just write a stub record to the queue and then actually write the full message to either Azure Table Storage, Azure SQL Database or Azure DocumentDB,使用队列存根作为识别完整消息存储位置的方法。
- 使用 Worker Role to read the queue 并将消息发送到 Mixpanel API。当 Mixpanel 关闭时,不要从队列中弹出存根,它会被重新处理。如果 Mixpanel API 已启动,请使用存根提取完整消息并发送到 Mixpanel API,然后从队列中删除存根。
这是一道一般性的设计题。我目前正在将跟踪事件从我的服务器(C# web api 托管在 azure 上)发送到 Mixpanel(使用 Mixpanel.NET 包:https://github.com/chrisnicola/Mixpanel.NET)。
这在大多数情况下工作正常。但是,它并不像我希望的那样健壮: 1. 虽然很小,但它不必要地减慢了我的服务器速度,因为事件是在 API 的正常使用期间发送的。 2.如果mixpanel宕机,事件丢失
解决这些问题的最佳方法是什么?我在想我可以在我的服务器上缓存事件并最终将它们发送到 Mixpanel。这是一个好方法吗?猜测我需要使用某种类型的持久存储以防我的服务器在发送之前出现故障。 Azure 队列对此有好处吗?
提前致谢。
- 根据消息的大小,您可以将它们写入 Azure Storage Queue or Azure Service Bus. If your message is too large to go on the queue on its own you could just write a stub record to the queue and then actually write the full message to either Azure Table Storage, Azure SQL Database or Azure DocumentDB,使用队列存根作为识别完整消息存储位置的方法。
- 使用 Worker Role to read the queue 并将消息发送到 Mixpanel API。当 Mixpanel 关闭时,不要从队列中弹出存根,它会被重新处理。如果 Mixpanel API 已启动,请使用存根提取完整消息并发送到 Mixpanel API,然后从队列中删除存根。