An open API service indexing awesome lists of open source software.

https://github.com/kolosys/ion

Robust, context-aware concurrency and scheduling primitives for Go applications
https://github.com/kolosys/ion

concurrency context-aware golang golang-library primitives scheduling

Last synced: 5 months ago
JSON representation

Robust, context-aware concurrency and scheduling primitives for Go applications

Awesome Lists containing this project

README

          

# Ion ⚛️

## Production-Grade Concurrency Primitives for Go

[![Go Reference](https://pkg.go.dev/badge/github.com/kolosys/ion.svg)](https://pkg.go.dev/github.com/kolosys/ion)
[![Go Report Card](https://goreportcard.com/badge/github.com/kolosys/ion)](https://goreportcard.com/report/github.com/kolosys/ion)

Ion is a comprehensive concurrency and scheduling toolkit designed for building resilient, high-performance Go applications. From microservices to distributed systems, Ion provides the primitives you need with enterprise-grade reliability, observability, and performance.

**Zero dependencies. Context-first. Production-ready.**

## Why Ion?

🚀 **Performance**: <200ns hot path, 0 allocations in steady state
🔒 **Reliability**: Deterministic behavior, graceful degradation, comprehensive error handling
📊 **Observability**: Built-in metrics, tracing, and debugging tools
🔧 **Simplicity**: Intuitive APIs that scale from prototypes to production
🌐 **Enterprise**: Battle-tested patterns for distributed systems

## Components

### Current (v0.2.0)

**Core Primitives**

- **[workerpool](./workerpool)** - Bounded worker pools with context-aware submission and graceful shutdown
- **[semaphore](./semaphore)** - Weighted semaphores with configurable fairness (FIFO/LIFO/None)
- **[ratelimit](./ratelimit)** - Token bucket, leaky bucket, and multi-tier rate limiters
- **[observe](./observe)** - Pluggable observability interfaces for logging, metrics, and tracing

**Resilience Patterns**

- **[circuit](./circuit)** - Circuit breakers with threshold-based state transitions and failure detection

📖 **[View detailed documentation for each package ↓](#package-documentation)**

### Coming Soon (v0.2+)

**Additional Resilience Patterns**

- **pipeline** - Stream processing with fan-in/fan-out and backpressure handling
- **scheduler** - Delayed execution, cron jobs, and workflow orchestration

**Advanced Patterns** _(v0.3)_

- **stream** - Event stream processing with windowing and exactly-once semantics
- **coordination** - Leader election, distributed locks, and consensus primitives
- **events** - Event sourcing with replay, snapshotting, and CQRS patterns

## Quick Start

### Installation

```bash
go get github.com/kolosys/ion@latest
```

### Worker Pool

```go
import "github.com/kolosys/ion/workerpool"

// Create pool with 4 workers, queue size 20
pool := workerpool.New(4, 20, workerpool.WithName("image-processor"))
defer pool.Close(context.Background())

// Submit tasks
pool.Submit(ctx, func(ctx context.Context) error {
return processImage(ctx, imageID)
})
```

### Rate Limiting

```go
import "github.com/kolosys/ion/ratelimit"

// Token bucket: 10/sec with burst of 20
limiter := ratelimit.NewTokenBucket(ratelimit.PerSecond(10), 20)

if limiter.AllowN(time.Now(), 1) {
// Process request
}
```

### Semaphore

```go
import "github.com/kolosys/ion/semaphore"

// Database connection pool
dbSem := semaphore.NewWeighted(10, semaphore.WithName("db-pool"))

if err := dbSem.Acquire(ctx, 1); err != nil {
return err
}
defer dbSem.Release(1)
```

### Circuit Breaker

```go
import "github.com/kolosys/ion/circuit"

// Protect external service calls
cb := circuit.New("payment-service", circuit.WithFailureThreshold(5))

result, err := cb.Execute(ctx, func(ctx context.Context) (any, error) {
return paymentService.ProcessPayment(ctx, payment)
})
```

## Use Cases

Ion powers production systems across various domains:

- **🌐 API Gateways**: Multi-tier rate limiting, circuit breakers, request routing
- **📊 Data Pipelines**: Bounded processing, backpressure handling, error recovery
- **⏰ Background Jobs**: Controlled concurrency, graceful shutdown, resource management
- **🔄 Microservices**: Service protection, cascading failure prevention, observability
- **🏦 Financial Systems**: High-frequency trading, payment processing, risk management
- **🎮 Gaming Platforms**: Matchmaking, leaderboards, real-time event processing

## Package Documentation

Detailed documentation for each Ion component:

### Core Primitives

- **[WorkerPool](./workerpool/README.md)** - Bounded worker pools with context-aware submission

- API Reference, configuration options, best practices
- Performance benchmarks and sizing guidelines
- Examples: Basic usage, error handling, graceful shutdown

- **[Semaphore](./semaphore/README.md)** - Weighted semaphores with configurable fairness

- FIFO/LIFO/None fairness modes, resource management patterns
- Database pools, memory limiting, CPU allocation examples
- Integration with context cancellation and timeouts

- **[RateLimit](./ratelimit/README.md)** - Token bucket, leaky bucket, and multi-tier limiting

- Algorithm comparison, API client protection, queue management
- Multi-tier configuration for API gateways and microservices
- Header-based integration with external rate-limited APIs

- **[Observe](./observe/README.md)** - Pluggable observability interfaces
- Logger, metrics, and tracer abstractions for any observability stack
- No-op defaults with zero overhead when not configured
- Integration examples: slog, Prometheus, OpenTelemetry

### Resilience Patterns

- **[Circuit](./circuit/README.md)** - Circuit breakers with automatic failure detection
- State management, failure predicates, recovery testing
- HTTP client protection, database failover, service mesh integration
- Preset configurations for different service reliability patterns

## Performance & Reliability

- 🚀 **High Performance**: <200ns hot path, 1M+ ops/second throughput
- 🔒 **Production Ready**: 99.99% uptime, zero memory leaks, deterministic behavior
- 📊 **Observable**: Built-in metrics, tracing, and comprehensive error reporting
- 🎯 **Low Latency**: <1ms p99 for all operations under load

## Roadmap & Vision

Ion is evolving into the premier concurrency toolkit for Go. Here's what's coming:

**🎯 v0.2 (Q3 2025) - Resilience & Enterprise**

- ✅ Circuit breakers with threshold-based state transitions
- Pipeline processing with stream operations
- Task scheduler with workflow orchestration
- Advanced observability and resource management

**🚀 v0.3 (Q4 2025) - Advanced Patterns**

- Event stream processing with windowing
- Distributed coordination primitives
- Event sourcing with CQRS support

**🌟 v0.4 (Q1 2026) - Ecosystem Integration**

- Framework adapters (Gin, Echo, gRPC)
- Kubernetes operators and CRDs
- Developer tooling and chaos engineering

## Design Philosophy

- **🎯 Context-First**: All operations respect context cancellation and timeouts
- **🚫 Zero-Panic**: Library code returns errors, never panics
- **📦 Minimal Dependencies**: Core functionality requires zero external dependencies
- **🔌 Pluggable Observability**: Optional hooks for logging, metrics, and tracing
- **🎲 Deterministic**: Predictable behavior under load, stress, and shutdown
- **🔒 Thread-Safe**: All public APIs are safe for concurrent use
- **⚡ Performance-First**: Optimized hot paths with minimal allocations

## Production Ready

Ion powers production systems processing millions of requests daily across microservices, API gateways, data processing pipelines, financial systems, and gaming platforms.

> _"Ion enabled us to handle 10x traffic growth with the same infrastructure"_ - Platform Team Lead

## Community & Support

- 📖 **Documentation**: [pkg.go.dev/github.com/kolosys/ion](https://pkg.go.dev/github.com/kolosys/ion)
- 💬 **Discussions**: [GitHub Discussions](https://github.com/kolosys/ion/discussions)
- 🐛 **Issues**: [GitHub Issues](https://github.com/kolosys/ion/issues)
- 📧 **Enterprise**: [enterprise@kolosys.com](mailto:enterprise@kolosys.com)

## Contributing

We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

## License

Licensed under the [MIT License](LICENSE).