Skip to content

Conversation

@Sambhram1
Copy link

Add Message Acknowledgment for Exactly-Once Processing

Summary

Implements message acknowledgment mechanism to support exactly-once processing guarantees, addressing the autoscaling feature (PR #202) where actors with pending messages could be dropped.

Changes

Core Implementation

  • SignedMessage: Added ack(), acknowledge(), and is_acknowledged() methods
  • BastionContext: Added message_processed(&SignedMessage) convenience method
  • ContextState: Added unacknowledged message counter for autoscaling integration

API Usage

Option 1 - Direct acknowledgment:

let msg = ctx.recv().await?;
msg.ack();

Option 2 - Context-based:

let msg = ctx.recv().await?;
ctx.message_processed(&msg);

Benefits

✅ Exactly-once message processing
✅ Safer autoscaling (prevents dropping actors with pending work)
✅ Thread-safe atomic operations
✅ Backward compatible (opt-in feature)
✅ Comprehensive tests and examples

Files Changed

  • src/bastion/src/envelope.rs - Added acknowledgment to SignedMessage
  • src/bastion/src/context.rs - Added tracking and context method
  • src/bastion/src/message.rs - Pattern matching updates
  • src/bastion/examples/message_acknowledgment.rs - Working example
  • src/bastion/tests/message_acknowledgment.rs - Test suite
  • Documentation files

Testing

cargo test message_acknowledgment
cargo run --example message_acknowledgment

Autoscaling Integration

The unacknowledged message counter enables autoscaling to check if actors are safe to remove:

// Only remove actors with no pending messages
if state.unacknowledged_count() == 0 {
    // Safe to remove actor
}

Breaking Changes

None. Fully backward compatible - existing code works unchanged.


Ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant