Service Overview
Internal API Server
Manages computation state in local Spanner
Computation Control Server
Coordinates multi-party computation with peers
Requisition Fulfillment Server
Receives encrypted data from EDPs
Async Computation Control
Asynchronous computation coordination
Internal API Server
Image:duchy/internal-apiService Name:
{duchy-name}-internal-api-serverPort: 8443 (gRPC), 8080 (health)
Purpose
The Internal API Server is the database access layer for the duchy. It provides internal gRPC services for managing computation state, storing requisition metadata, and tracking computation progress.Responsibilities
- Provide CRUD operations for computations in Spanner
- Manage computation tokens and work locking
- Store requisition metadata and fulfillment status
- Track computation statistics and metrics
- Manage continuation tokens for resumable operations
- Execute database schema migrations via init containers
Key Services
Implemented insrc/main/kotlin/org/wfanet/measurement/duchy/service/internal/:
ComputationsService
ComputationsService
File:
computations/ComputationsService.ktCore service for computation lifecycle management:- Create new computations
- Update computation state and stage
- Claim work via token mechanism
- Query computations by state
- Mark computations as completed or failed
- Delete old computations (via cleaner)
ComputationStatsService
ComputationStatsService
File:
computationstats/ComputationStatsService.ktTracks metrics and performance data:- Record stage execution times
- Track retry attempts
- Monitor computation progress
- Provide debugging and monitoring data
ContinuationTokensService
ContinuationTokensService
Manages resumable operations:
- Store tokens for long-running operations
- Enable idempotent retry of failed operations
- Support streaming operations with pagination
Configuration Flags
Storage Backend
The Internal API Server manages two storage systems: Spanner Database:- Computations table with state machine
- Requisitions table with metadata
- Computation stats for monitoring
- Token management for work claiming
- Encrypted sketch data
- Intermediate computation results
- Protocol message payloads
Network Policy
Only accessible from:- Herald daemon
- Mill job scheduler
- Mill workers (LLv2, HMSS)
- Computation control servers
- Requisition fulfillment server
- Computations cleaner CronJob
Computation Control Server
Image:duchy/computation-controlService Name:
{duchy-name}-computation-control-serverPort: 8443 (gRPC), 8080 (health)
Type: External Service
Purpose
The Computation Control Server enables peer-to-peer coordination between duchies during multi-party computation. It exposes endpoints that peer duchies call to advance computations through protocol stages.Responsibilities
- Accept computation data from peer duchies
- Validate incoming protocol messages
- Update local computation state based on peer input
- Enforce protocol stage ordering
- Handle retry and error scenarios
- Verify peer duchy identity and authorization
API Design
Implemented insrc/main/kotlin/org/wfanet/measurement/duchy/service/system/v1alpha/:
ComputationControlService
ComputationControlService
File:
ComputationControlService.ktMain service for inter-duchy coordination:AdvanceComputation: Push computation to next stage- Accept encrypted protocol payloads from peers
- Validate computation participant signatures
- Coordinate with AsyncComputationControlService
- Sender duchy is authorized participant
- Computation exists and is in expected state
- Protocol stage transition is valid
AdvanceComputationRequestHeaders
AdvanceComputationRequestHeaders
File:
AdvanceComputationRequestHeaders.ktMetadata validation for peer requests:- Duchy identity verification
- Protocol version compatibility
- Request signature validation
Protocol Coordination
The Computation Control Server is called by mill workers in peer duchies:- Duchy A completes shuffle phase
- Duchy A calls Duchy B’s Computation Control endpoint with shuffled data
- Duchy B validates the request
- Duchy B stores encrypted data in blob storage
- Duchy B updates computation state to enable next stage
Configuration Flags
Security
- Mutual TLS: All peer connections use mTLS
- Certificate Validation: Duchy identity verified via certificates
- Request Signing: Protocol messages include cryptographic signatures
- Replay Protection: Computation tokens prevent replay attacks
Async Computation Control Server
Image:duchy/async-computation-controlService Name:
{duchy-name}-async-computation-control-serverPort: 8443 (gRPC), 8080 (health)
Purpose
The Async Computation Control Server handles asynchronous computation control operations. It works in conjunction with the synchronous Computation Control Server to manage long-running protocol operations.Responsibilities
Implemented insrc/main/kotlin/org/wfanet/measurement/duchy/service/internal/computationcontrol/:
- Asynchronous advancement of computation stages
- Non-blocking protocol coordination
- Background processing of protocol messages
- Decoupling of synchronous peer requests from local processing
AsyncComputationControlService
AsyncComputationControlService
File:
AsyncComputationControlService.ktProvides asynchronous computation control:- Queues protocol operations for background processing
- Enables non-blocking peer coordination
- Manages computation state transitions asynchronously
ProtocolStages
ProtocolStages
File:
ProtocolStages.ktDefines protocol stage state machines:- Valid stage transitions for each protocol
- Stage-specific validation logic
- Protocol completion detection
Configuration
Requisition Fulfillment Server
Image:duchy/requisition-fulfillmentService Name:
{duchy-name}-requisition-fulfillment-serverPort: 8443 (gRPC), 8080 (health)
Type: External Service
Purpose
The Requisition Fulfillment Server accepts encrypted event data from Event Data Providers (EDPs). It provides the API endpoint that EDPs call to upload their encrypted sketches for measurements.Responsibilities
- Accept requisition fulfillment requests from EDPs
- Validate EDP authorization for requisitions
- Receive and store encrypted sketch data
- Verify data encryption and signatures
- Update requisition fulfillment status
- Notify Kingdom of successful fulfillment
API Implementation
Implemented insrc/main/kotlin/org/wfanet/measurement/duchy/service/api/v2alpha/:
RequisitionFulfillmentService
RequisitionFulfillmentService
File:
RequisitionFulfillmentService.ktMain service for data ingestion:FulfillRequisition: Upload encrypted sketch data- Validate EDP certificate and authorization
- Verify requisition exists and is pending
- Store encrypted data in blob storage
- Update internal requisition metadata
- Confirm fulfillment with Kingdom
- Only authorized EDPs can fulfill requisitions
- Data is properly encrypted with duchy’s public key
- Requisition can only be fulfilled once
- Kingdom is notified upon successful upload
Data Flow
Configuration Flags
Authentication
- EDP Certificates: EDPs authenticate using X.509 certificates
- AKID Mapping: Authority Key Identifier maps to EDP principal
- Requisition Authorization: Only the assigned EDP can fulfill a requisition
Service Interaction Diagram
Common Configuration Patterns
Duchy Identity
All services require duchy identity configuration:TLS Configuration
Mutual TLS for all services:Internal API Client
Most services connect to the Internal API Server:Blob Storage
Services that handle computation data need blob storage:Deployment Architecture
All duchy services are defined insrc/main/k8s/duchy.cue:
Service Naming
Services are prefixed with duchy name:worker1-internal-api-serverworker1-computation-control-server- etc.
Dependencies
Services have explicit dependencies:- Computation Control depends on: Internal API, Async Computation Control
- Requisition Fulfillment depends on: Internal API
- Mill Job Scheduler depends on: Internal API, Computation Control
Health Checks
All services expose:- gRPC health check service
- HTTP health endpoint on port 8080
- Kubernetes readiness and liveness probes
Monitoring and Observability
gRPC Metrics
Request rates, latencies, error rates per service method
Computation Stats
Stage execution times, retry counts, success rates
Storage Metrics
Spanner query performance, blob storage usage
Verbose Logging
Optional detailed gRPC logging for debugging
Security Best Practices
Duchy services handle sensitive cryptographic operations. Follow security best practices for production deployments.
- Certificate Management: Use short-lived certificates with automated rotation
- Network Policies: Enforce strict NetworkPolicies limiting service communication
- Secrets Management: Use external secret management (e.g., Google Secret Manager)
- Audit Logging: Enable comprehensive audit logs for all API operations
- Resource Limits: Set appropriate CPU/memory limits to prevent DoS
Next Steps
Duchy Daemons
Learn about Herald and Mill Job Scheduler
Mill Protocols
Understand cryptographic protocols