[KongchangAI]
· 2 min read· 1,065 words

TypeScript + Stateful Actors: Building a Highly Reliable Group Messaging Tracker

TypeScript + Stateful Actors: Building a Highly Reliable Group Messaging Tracker

Crew Cast uses TypeScript and Stateful Actors to build a durable group messaging delivery tracker.

Crew Cast is an open-source project solving async event tracking in group messaging. It creates a Stateful Actor per group task, correlating all events via group_message_id to turn a chaotic async stream into an orderly durable workflow. It uses KV storage for webhook routing and SQL for reporting, with replay-safe webhooks and Ed25519 verification. The author seeks feedback on lifecycle cleanup and retention.

Tracking delivery status for group messages has always been a headache for developers: one message sent to many people, each recipient may have a different status, plus async events like replies, failures, and retries. Recently, an open-source project called Crew Cast demonstrated how to use TypeScript and Stateful Actors to turn this chaotic stream of async events into a durable workflow, making group tracking clear and controllable.

reddit source: built a durable Group MMS delivery tracker with TypeScript and Stateful Actors

Core Design: One Actor per Group Message Task

Crew Cast's core idea is to create a Stateful Actor for each group messaging task. The Actor model is naturally suited to handling concurrency and state management; each Actor independently maintains the state of the group task it is responsible for, avoiding race conditions caused by shared state. The project uses group_message_id as the link for event correlation—all events related to that group message, whether delivery receipts, user replies, or webhook retries, are routed to the corresponding Actor via this ID.

According to the project author, this design allows all async results of a group messaging task to be aggregated in an orderly manner onto a "delivery dashboard," clearly showing who has received, who has replied, who failed to send, and whose status is still unknown.

The Stateful Actor model is a concurrency computation model in which each Actor is an independent entity with its own private state and mailbox, communicating with other Actors through asynchronous messages. Actors do not share memory, so race conditions are naturally avoided. In Crew Cast, each group messaging task corresponds to an Actor that processes all related events (such as delivery receipts and replies) serially, ensuring the order and consistency of state updates. This model is particularly suitable for workflows that need to maintain long-running state, because Actors can persist their state and recover after failures.

Tech Stack and Key Mechanisms

Crew Cast uses a variety of storage and verification mechanisms to ensure reliability:

  • KV storage: Used for routing webhooks to Actors, quickly mapping external events to the corresponding processing unit.
  • SQL storage: Supports recipient-level report queries for easy statistics and analysis.
  • Replay-safe webhook handling: Ensures duplicate webhooks do not cause duplicate state updates or errors.
  • Scheduled checks: For unresolved states (such as long periods without a receipt), the system periodically checks and updates.
  • Ed25519 verification: In live mode, performs signature verification on webhooks to ensure the event source is trustworthy.
  • Demo mode: Does not send real messages, making it easy for developers to test and try out.

Together, these mechanisms build a durable, auditable tracking system. The author specifically notes that this pattern can be generalized to field service dispatch, incident response, event team management, delivery teams, and any workflow scenario where "one message produces multiple async results."

Ed25519 is a digital signature algorithm based on elliptic curves, known for its high security and performance. In webhook handling, Ed25519 is used to verify the authenticity of the event source: the sender signs the webhook payload with a private key, and the receiver verifies the signature with a public key. This prevents malicious third parties from forging events, ensuring only trusted sources can update Actor state. Ed25519 signatures are short (64 bytes) and fast to verify, making them suitable for high-concurrency scenarios.

Replay-safe webhook handling means the system can identify and ignore duplicate webhook events, preventing the same event from being processed multiple times and causing state errors. Common implementations include assigning a unique ID to each event and recording processed IDs, or using idempotent operations. In Crew Cast, combined with group_message_id and event IDs, it ensures that even if a webhook is retried due to network issues, Actor state will not be updated repeatedly, thereby guaranteeing eventual consistency.

Open Questions: Lifecycle Cleanup and Retention Strategy

Although Crew Cast has implemented its core functionality, the author actively seeks feedback in the community, with particular attention to the Actor model design and the lifecycle cleanup and retention strategy for completed group messaging threads. For long-running systems, how to promptly release resources occupied by completed tasks and how to retain historical data for auditing are engineering trade-offs that need to be weighed. The project has not yet provided a clear solution, which also offers developers an opportunity to join the discussion and contribute.

Actor lifecycle management is a common challenge in the Actor model, involving the creation, activation, deactivation, and destruction of Actors. For Actors of completed group messaging tasks, long-term retention consumes memory and storage resources, but immediate destruction may lose historical data needed for auditing. Common strategies include: automatically deactivating Actors after an idle timeout (with state persisted to storage), or retaining for a period based on business needs before archiving. The feedback sought by the Crew Cast author is precisely about how to balance resource release with data retention.

Takeaways for Developers

Crew Cast's value lies in providing a reusable pattern: using the Actor model to manage stateful async workflows, combining KV and SQL storage to address routing and query needs, and improving reliability through replay safety and signature verification. For teams building message notifications, task dispatch, or collaboration tools, this open-source example is worth studying in depth. The code is open-sourced on GitHub, and developers can directly reference the implementation or extend it.

As distributed systems and event-driven architectures become more widespread, how to elegantly handle async state consistency will become a challenge for more developers. Crew Cast's practice may offer you an approach.

One-line Summary

Crew Cast uses TypeScript and Stateful Actors to build a durable group messaging delivery tracking system.

Paragraph Summary

Crew Cast is an open-source project aimed at solving the challenge of tracking async events in group messaging. It creates a Stateful Actor for each group messaging task, correlating all events (such as delivery receipts, replies, and failures) through group_message_id, turning a chaotic async stream into an orderly durable workflow. The tech stack includes KV storage for webhook routing, SQL storage for report queries, and implements replay-safe webhook handling and Ed25519 signature verification for reliability. The project also provides a demo mode for easy testing. The author publicly seeks feedback on Actor lifecycle cleanup and retention strategy. This pattern can be generalized to scenarios such as field service dispatch and incident response, offering developers a reusable approach to handling async state consistency.

#TypeScript#Stateful Actors#group messaging#webhook#durable workflow#Ed25519#async events#delivery tracking
Share:

Related articles