Overview
Kingdom daemons are implemented as Kubernetes CronJobs that run on a scheduled basis. They communicate with the Kingdom Data Server to perform database operations.Completed Measurements Deletion
Removes old completed measurements based on TTL
Pending Measurements Cancellation
Cancels stale pending measurements
Exchanges Deletion
Cleans up old panel exchange data
Completed Measurements Deletion
Image:kingdom/completed-measurements-deletionSchedule:
15 * * * * (Hourly, 15 minutes past the hour)CronJob Name:
completed-measurements-deletion
Purpose
This job periodically deletes completed measurements that have exceeded their time-to-live (TTL) threshold. This helps:- Reduce database storage costs
- Maintain query performance
- Comply with data retention policies
- Remove unnecessary historical data
Configuration Parameters
Time to Live (TTL)
Time to Live (TTL)
Flag:
Default: 180 days
Description: How long to retain completed measurements before deletion.Measurements in terminal states (SUCCEEDED, FAILED, CANCELLED) older than this threshold are eligible for deletion.
--time-to-live=180dDefault: 180 days
Description: How long to retain completed measurements before deletion.Measurements in terminal states (SUCCEEDED, FAILED, CANCELLED) older than this threshold are eligible for deletion.
Max Deletions Per RPC
Max Deletions Per RPC
Flag:
Default: 25
Description: Maximum number of measurements to delete in a single RPC call.This prevents overwhelming the database with large batch deletes and provides rate limiting.
--max-to-delete-per-rpc=25Default: 25
Description: Maximum number of measurements to delete in a single RPC call.This prevents overwhelming the database with large batch deletes and provides rate limiting.
Dry Run Mode
Dry Run Mode
Flag:
Default: false
Description: When enabled, logs which measurements would be deleted without actually deleting them.Useful for testing retention policies before applying them.
--dry-run=falseDefault: false
Description: When enabled, logs which measurements would be deleted without actually deleting them.Useful for testing retention policies before applying them.
Operation
- Query: Identifies completed measurements older than TTL
- Batch: Groups deletions into batches of
max-to-delete-per-rpc - Delete: Removes measurements via the Kingdom Data Server API
- Log: Records deletion operations for audit purposes
Example Configuration
The hourly schedule ensures regular cleanup without creating excessive database load. The :15 timing is offset from other jobs to distribute load.
Pending Measurements Cancellation
Image:kingdom/pending-measurements-cancellationSchedule:
45 * * * * (Hourly, 45 minutes past the hour)CronJob Name:
pending-measurements-cancellation
Purpose
This job automatically cancels measurements that have been stuck in pending states for too long. This prevents:- Resource leaks from abandoned measurements
- Confusion from stale pending measurements
- Indefinite waiting on failed or unresponsive participants
Configuration Parameters
Time to Live (TTL)
Time to Live (TTL)
Flag:
Default: 15 days
Description: How long to keep measurements in pending states before cancellation.Measurements that have been pending longer than this duration are automatically cancelled.
--time-to-live=15dDefault: 15 days
Description: How long to keep measurements in pending states before cancellation.Measurements that have been pending longer than this duration are automatically cancelled.
Dry Run Mode
Dry Run Mode
Flag:
Default: false
Description: When enabled, logs which measurements would be cancelled without actually cancelling them.
--dry-run=falseDefault: false
Description: When enabled, logs which measurements would be cancelled without actually cancelling them.
Pending States
The job targets measurements in non-terminal states such as:PENDING_REQUISITION_PARAMS: Waiting for requisition parametersPENDING_REQUISITION_FULFILLMENT: Waiting for EDP dataPENDING_PARTICIPANT_CONFIRMATION: Waiting for duchy confirmationPENDING_COMPUTATION: Queued but not yet computing
Operation
- Identify: Finds measurements in pending states older than TTL
- Validate: Confirms measurements are truly stale (not just slow)
- Cancel: Transitions measurements to CANCELLED state
- Notify: May trigger notifications to measurement requestors
- Log: Records cancellation for audit and debugging
Example Configuration
The 15-day TTL is shorter than the completed measurements TTL (180d) because pending measurements consume active resources and should be resolved or cancelled more quickly.
Exchanges Deletion
Image:kingdom/exchanges-deletionSchedule:
40 6 * * * (Daily at 6:40 AM)CronJob Name:
exchanges-deletion
Purpose
This job cleans up old panel exchange data to:- Remove completed exchange workflows
- Free up storage from exchange intermediate data
- Maintain manageable exchange history
- Comply with data retention requirements
Configuration Parameters
Days to Live
Days to Live
Flag:
Default: 100 days
Description: Number of days to retain exchange data.Panel exchanges older than this are eligible for deletion.
--days-to-live=100Default: 100 days
Description: Number of days to retain exchange data.Panel exchanges older than this are eligible for deletion.
Dry Run Mode
Dry Run Mode
Flag:
Default: false
Description: When enabled, logs which exchanges would be deleted without actually deleting them.
--dry-run=falseDefault: false
Description: When enabled, logs which exchanges would be deleted without actually deleting them.
Exchange Data
Panel exchanges involve:- Exchange workflow definitions
- Exchange steps and their execution history
- Exchange step attempts and retry information
- Intermediate computation results
- Metadata and checkpoints
Operation
- Query: Identifies exchanges older than the retention period
- Cascade: Deletes related exchange steps, attempts, and metadata
- Clean: Removes associated blob storage (if applicable)
- Log: Records deletion operations
Example Configuration
The daily schedule (rather than hourly) reflects that panel exchanges are longer-running workflows that don’t require frequent cleanup.
Common Configuration
All Kingdom daemons share common configuration patterns:Authentication
Logging
Kubernetes Configuration
All CronJobs are configured with:- Secrets: Access to kingdom TLS certificates and keys
- Network Policies: Restricted to communicate only with Data Server
- Resource Limits: CPU and memory constraints
- Concurrency Policy: Typically
Forbidto prevent overlapping runs - Success/Failure History: Limited retention of job history
Deployment Pattern
Kingdom daemons follow a consistent deployment pattern defined inkingdom.cue:
- Consistent naming conventions
- Shared secret management
- Unified image versioning
- Standard container configuration
Monitoring and Alerting
Job Success Rate
Monitor CronJob completion status and failure rates
Deletion Metrics
Track number of records deleted per run
Execution Duration
Alert on jobs that take unusually long to complete
Dry Run Testing
Use dry-run mode to validate before enabling deletions
Best Practices
Retention Policy Design
Align with Business Requirements
Align with Business Requirements
Set TTL values based on:
- Legal/compliance retention requirements
- Storage budget constraints
- Query performance needs
- Historical analysis requirements
Test with Dry Run
Test with Dry Run
Always test retention policies with
--dry-run=true before enabling deletions:Monitor Storage Impact
Monitor Storage Impact
Track database storage metrics before and after deletion jobs to validate effectiveness.
Troubleshooting
Job Not Running:- Enable dry-run mode immediately
- Review TTL configuration
- Check for clock skew or incorrect timestamps
- Restore from backups if necessary
- Verify TTL is configured correctly
- Check that jobs are running on schedule
- Verify network connectivity to Data Server
- Review job logs for errors
Network Policies
Each daemon has a corresponding network policy that:- Allows ingress: None (jobs initiate outbound connections only)
- Allows egress to:
gcp-kingdom-data-server - Denies all other traffic
Next Steps
Kingdom Overview
Return to Kingdom architecture overview
Duchy Daemons
Learn about Duchy background jobs