Async vs Sync
The Functor SDK provides both synchronous and asynchronous interfaces for all operations. Choose the right pattern based on your application's needs, performance requirements, and concurrency patterns.
Interface Overview
Synchronous Interface
Simple, blocking operations that are easy to understand and debug:
Asynchronous Interface
Non-blocking operations that enable concurrent execution:
When to Use Each Interface
Use Synchronous When:
- Simple scripts: One-off operations or simple automation
- Sequential operations: Operations that must happen in order
- Debugging: Easier to debug and understand execution flow
- Learning: Getting started with the SDK
- Blocking is acceptable: When waiting for results is not a problem
Use Asynchronous When:
- Web applications: Server applications that handle multiple requests
- Concurrent operations: Multiple operations that can run simultaneously
- High throughput: Applications that need to process many requests
- Real-time applications: Applications that need to remain responsive
- Batch processing: Processing multiple items concurrently
Performance Comparison
Sequential Operations
Concurrent Operations
Advanced Async Patterns
Async Context Manager
Async with Error Handling
Async Batch Processing
Hybrid Patterns
Sync Client with Async Operations
Async Client with Sync Operations
Performance Optimization
Connection Pooling
Rate Limiting
Migration Guide
From Sync to Async
From Async to Sync
Best Practices
Async Best Practices
- Use async context managers: Ensure proper resource cleanup
- Batch operations: Group related operations together
- Handle exceptions properly: Use try-catch with async operations
- Respect rate limits: Add delays between batches if needed
- Use asyncio.gather(): For concurrent operations
- Avoid blocking operations: Don't mix sync and async unnecessarily
Sync Best Practices
- Use context managers: Ensure proper resource cleanup
- Handle exceptions: Always wrap operations in try-catch
- Keep operations simple: Avoid complex nested operations
- Use appropriate timeouts: Prevent hanging operations
- Consider async for batch operations: When processing many items
Next Steps
- Client Reference - Configure client for your chosen interface
- Queries Namespace - Apply async/sync patterns to queries
- Error Handling - Handle errors in async/sync contexts
- Ingestion Namespace - Batch upload operations efficiently