What are Services?
Services are the fundamental building blocks of Infinitic. A service is a Java or Kotlin class that implements business logic and performs tasks. Services are executed by workers and can be called from workflows or clients.Key Concepts
Service Interface and Implementation
Services in Infinitic follow an interface-implementation pattern:- Interface: Defines the contract for your service methods
- Implementation: Contains the actual business logic
Service Name
By default, Infinitic uses the fully qualified class name as the service name. You can customize this using the@Name annotation:
@Name annotation can also be applied to individual methods:
Service Features
Infinitic services support several advanced features:1. Task Context Access
Every task has access to contextual information through theTask object, including task ID, retry information, workflow context, and more.
Learn more about Task Context →
2. Delegated Tasks
For long-running operations or external system integrations, you can delegate task completion to external systems using the@Delegated annotation.
Learn more about Delegated Tasks →
3. Batch Processing
Optimize performance by processing multiple tasks together using the@Batch annotation. Perfect for database operations, API calls, or any operation that benefits from batching.
Learn more about Batching →
4. Retry and Timeout Configuration
Services support automatic retry mechanisms and timeout configurations:Service Registration
Services must be registered with a worker before they can execute tasks. Here’s how to configure services in your worker:Configuration Options
- name: The service name (must match the name used by clients)
- factory: A lambda that creates service instances
- concurrency: Number of parallel task executions (default: 1)
- withRetry: Default retry policy for all methods
- withTimeout: Default timeout for all methods
Best Practices
Keep Services Stateless
Service instances should be stateless. Workers may create multiple instances for parallel execution, so storing state in instance variables can lead to unexpected behavior.Use Dependency Injection
For services that need external dependencies, use the factory pattern:Handle Exceptions Appropriately
Exceptions thrown from service methods trigger retry mechanisms. Use exceptions for transient failures but return error values for permanent failures:Next Steps
Defining Services
Learn the details of creating service interfaces and implementations
Service Context
Access task metadata, workflow information, and more
Delegated Tasks
Integrate with external systems for long-running operations
Batching
Process multiple tasks efficiently with batch operations