syros 1.0.1

Syros - Distributed Coordination Service
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# Syros - Distributed Coordination Service


**Syros** is a distributed coordination platform built in Rust, offering robust solutions for modern distributed systems.

## Project Status


### Implemented Components


- **Core Engine**: Lock Manager, Saga Orchestrator, Event Store, Cache Manager
- **REST APIs**: Complete endpoints with health checks and metrics
- **gRPC API**: Complete gRPC services with Volo
- **WebSocket**: Real-time WebSocket connection support
- **Flexible Server**: Server selection and IP configuration
- **Configuration**: Flexible configuration system using environment variables or TOML
- **Error Handling**: Robust error handling with descriptive codes
- **Observability**: Built-in Prometheus metrics and structured logging
- **Security**: JWT-based authentication and API Key authorization
- **SDKs**: Native SDKs for Python, Node.js, Java, C#, and Go
- **Infrastructure**: Ready-to-use Docker and Kubernetes (Helm) configurations

## Key Features


### Distributed Lock Manager

Syros provides a high-performance, distributed lock manager using Redis as the backend. It supports lock acquisition with TTL, wait timeouts, and ownership verification, ensuring mutual exclusion across a cluster of services.

### Saga Orchestrator

Implement complex distributed transactions using the Saga pattern. Syros manages step execution, retries with customizable backoff strategies, and automatic compensation logic (rollback) if a step fails, maintaining eventual consistency in your microservices.

### Event Store

A persistent event sourcing engine powered by PostgreSQL. Append events to streams, retrieve event history with versioning, and build reactive systems by replaying events. Includes support for metadata and automatic versioning.

### Distributed Cache

A fast, tag-based distributed cache. Optimize your system by caching expensive computations, with support for TTL-based expiration and bulk invalidation by tags.

## Platform Architecture


### Big Picture - Architecture Overview


```mermaid
---
config:
  layout: elk
---
flowchart TB
 subgraph subGraph0["Client Applications"]
        WEB["Web Applications"]
        MOBILE["Mobile Apps"]
        CLI["CLI Tools"]
        SDK["SDK Clients"]
  end
  subgraph subGraph1["API Gateway Layer"]
        REST["REST API<br>Port 8080"]
        GRPC["gRPC API<br>Port 9090"]
        WS["WebSocket API<br>Port 8081"]
        GRAPHQL["GraphQL API<br>Port 8080/graphql"]
  end
  subgraph subGraph2["Core Services Layer"]
        LM["Lock Manager<br>Distributed Locks"]
        SO["Saga Orchestrator<br>Distributed Transactions"]
        ES["Event Store<br>Event Sourcing"]
        CM["Cache Manager<br>Distributed Cache"]
        SD["Service Discovery<br>Consul Integration"]
        RBAC["RBAC Manager<br>Role-Based Access Control"]
  end
  subgraph subGraph3["Middleware Layer"]
        AUTH["Auth Middleware<br>JWT &amp; API Keys"]
        RATE["Rate Limiting<br>Request Throttling"]
        CORS["CORS Handler<br>Cross-Origin Support"]
        METRICS["Metrics Collector<br>Prometheus Integration"]
  end
  subgraph subGraph4["Storage Layer"]
        REDIS[("Redis<br>Locks &amp; Cache")]
        POSTGRES[("PostgreSQL<br>Events &amp; Metadata")]
        ETCD[("etcd<br>Configuration")]
  end
  subgraph subGraph5["Observability Layer"]
        PROMETHEUS["Prometheus<br>Metrics Collection"]
        GRAFANA["Grafana<br>Dashboards"]
        JAEGER["Jaeger<br>Distributed Tracing"]
        LOGS["Structured Logging<br>JSON Format"]
  end
  subgraph subGraph6["Infrastructure Layer"]
        DOCKER["Docker Containers"]
        K8S["Kubernetes<br>Orchestration"]
        HELM["Helm Charts<br>Deployment"]
        CI["GitHub Actions<br>CI/CD Pipeline"]
  end
  subgraph subGraph7["SDK Layer"]
        PYTHON["Python SDK"]
        NODE["Node.js SDK"]
        JAVA["Java SDK"]
        CSHARP["C# SDK"]
        GO["Go SDK"]
  end
    WEB --> REST & WS
    MOBILE --> REST & WS
    CLI --> REST
    SDK --> REST & GRPC
    REST --> AUTH
    GRPC --> AUTH
    WS --> AUTH
    GRAPHQL --> AUTH
    AUTH --> RATE
    RATE --> CORS
    CORS --> METRICS
    METRICS --> LM & SO & ES & CM & SD & RBAC & PROMETHEUS
    LM --> REDIS
    CM --> REDIS
    ES --> POSTGRES
    SO --> POSTGRES
    SD --> ETCD
    RBAC --> POSTGRES
    PROMETHEUS --> GRAFANA
    LOGS --> JAEGER
    DOCKER --> K8S
    K8S --> HELM
    CI --> DOCKER
    PYTHON --> REST
    NODE --> REST
    JAVA --> GRPC
    CSHARP --> GRPC
    GO --> GRPC
     WEB:::clientLayer
     MOBILE:::clientLayer
     CLI:::clientLayer
     SDK:::clientLayer
     REST:::apiLayer
     GRPC:::apiLayer
     WS:::apiLayer
     GRAPHQL:::apiLayer
     LM:::coreLayer
     SO:::coreLayer
     ES:::coreLayer
     CM:::coreLayer
     SD:::coreLayer
     RBAC:::coreLayer
     AUTH:::middlewareLayer
     RATE:::middlewareLayer
     CORS:::middlewareLayer
     METRICS:::middlewareLayer
     REDIS:::storageLayer
     POSTGRES:::storageLayer
     ETCD:::storageLayer
     PROMETHEUS:::observabilityLayer
     GRAFANA:::observabilityLayer
     JAEGER:::observabilityLayer
     LOGS:::observabilityLayer
     DOCKER:::infrastructureLayer
     K8S:::infrastructureLayer
     HELM:::infrastructureLayer
     CI:::infrastructureLayer
     PYTHON:::sdkLayer
     NODE:::sdkLayer
     JAVA:::sdkLayer
     CSHARP:::sdkLayer
     GO:::sdkLayer
    classDef clientLayer fill:#e1f5fe
    classDef apiLayer fill:#f3e5f5
    classDef coreLayer fill:#e8f5e8
    classDef middlewareLayer fill:#fff3e0
    classDef storageLayer fill:#fce4ec
    classDef observabilityLayer fill:#f1f8e9
    classDef infrastructureLayer fill:#e0f2f1
    classDef sdkLayer fill:#fff8e1
```

### Data Flow and Interactions


```mermaid
sequenceDiagram
    participant Client as Client
    participant API as API Gateway
    participant Auth as Auth Middleware
    participant Core as Core Services
    participant Storage as Storage Layer
    participant Obs as Observability

    Note over Client,Obs: Typical Request Flow

    Client->>API: 1. HTTP/gRPC/WebSocket Request
    API->>Auth: 2. Authentication Validation
    Auth->>Auth: 3. Verify JWT/API Key
    Auth-->>API: 4. Valid Token
    
    API->>Core: 5. Process Request
    Core->>Storage: 6. Access Data
    Storage-->>Core: 7. Return Data
    Core-->>API: 8. Processed Response
    
    API->>Obs: 9. Record Metrics
    API-->>Client: 10. Final Response

    Note over Client,Obs: Example: Lock Acquisition

    Client->>API: POST /api/v1/locks
    API->>Auth: Validate Token
    Auth-->>API: Token OK
    API->>Core: LockManager.acquire_lock()
    Core->>Storage: Redis SET lock_key
    Storage-->>Core: Lock Acquired
    Core-->>API: LockResponse
    API->>Obs: Record Lock Metrics
    API-->>Client: 201 Created + Lock ID

    Note over Client,Obs: Example: WebSocket Event

    Client->>API: WebSocket Connect
    API->>Auth: Validate Token
    Auth-->>API: Token OK
    API->>Core: Subscribe to Events
    Core->>Storage: Monitor Changes
    Storage-->>Core: Data Changed
    Core-->>API: Event Notification
    API-->>Client: WebSocket Message
```

### Implemented Architecture Patterns


```mermaid
graph LR
    subgraph "Distributed Patterns"
        SAGA[Saga Pattern<br/>Distributed Transactions]
        LOCK[Distributed Locks<br/>Mutual Exclusion]
        EVENT[Event Sourcing<br/>Audit Trail]
        CACHE[Distributed Cache<br/>Performance]
    end

    subgraph "Communication Patterns"
        REST[REST API<br/>HTTP/JSON]
        GRPC[gRPC<br/>High Performance]
        WS[WebSocket<br/>Real-time]
        GRAPHQL[GraphQL<br/>Flexible Queries]
    end

    subgraph "Observability Patterns"
        METRICS[Metrics<br/>Prometheus]
        TRACING[Tracing<br/>Jaeger]
        LOGGING[Structured Logging<br/>JSON]
        HEALTH[Health Checks<br/>K8s Ready]
    end

    subgraph "Security Patterns"
        JWT[JWT Authentication<br/>Stateless]
        RBAC[RBAC Authorization<br/>Role-based]
        APIKEY[API Keys<br/>Service-to-Service]
        CORS[CORS<br/>Cross-Origin]
    end

    subgraph "Infrastructure Patterns"
        CONTAINER[Containerization<br/>Docker]
        ORCHESTRATION[Orchestration<br/>Kubernetes]
        CI[CI/CD<br/>GitHub Actions]
        HELM[Package Management<br/>Helm Charts]
    end

    SAGA --> REST
    LOCK --> GRPC
    EVENT --> WS
    CACHE --> GRAPHQL

    REST --> METRICS
    GRPC --> TRACING
    WS --> LOGGING
    GRAPHQL --> HEALTH

    METRICS --> JWT
    TRACING --> RBAC
    LOGGING --> APIKEY
    HEALTH --> CORS

    JWT --> CONTAINER
    RBAC --> ORCHESTRATION
    APIKEY --> CI
    CORS --> HELM
```

## Documentation


Complete documentation is available in the [`docs/`](docs/) folder:

- **[Quick Start Guide]docs/getting-started.md** - Installation and first steps
- **[REST API]docs/rest-api.md** - Complete REST API documentation
- **[gRPC API]docs/grpc-api.md** - High-performance gRPC interface
- **[WebSocket API]docs/websocket-api.md** - Real-time communication
- **[GraphQL API]docs/graphql-api.md** - Flexible GraphQL interface
- **[SDKs]docs/sdks.md** - SDKs for Python, Node.js, Java, C#, Go
- **[Observability]docs/observability.md** - Monitoring and metrics
- **[Architecture]docs/architecture.md** - Architecture overview
- **[Configuration]docs/configuration.md** - Advanced configuration
- **[Deployment]docs/deployment.md** - Deployment guides
- **[FAQ]docs/faq.md** - Frequently asked questions

### Prerequisites


-   **Rust**: Stable 1.70+
-   **Docker & Docker Compose**: For backing services
-   **Services**: Redis (Locks/Cache) and PostgreSQL (Saga/Events)

### Quick Start


The fastest way to get Syros running with all its dependencies is via Docker Compose:

```bash
# 1. Clone the repository

git clone https://github.com/wendelmax/syros.git
cd syros

# 2. Build and start all services

docker-compose up -d --build
```

Access the health check to verify everything is working:
```bash
curl http://localhost:8080/health
```

### Usage Examples


#### Acquire a Distributed Lock

```bash
curl -X POST http://localhost:8080/api/v1/locks \
  -H "Content-Type: application/json" \
  -d '{
    "key": "inventory_process_123",
    "owner": "worker_service_01",
    "ttl_seconds": 30
  }'
```

#### Start a Distributed Saga

```bash
curl -X POST http://localhost:8080/api/v1/sagas \
  -H "Content-Type: application/json" \
  -d '{
    "name": "order_fulfillment_saga",
    "steps": [
      {
        "name": "reserve_inventory",
        "service": "inventory_service",
        "action": "reserve",
        "compensation": "release_inventory",
        "timeout_seconds": 10
      },
      {
        "name": "charge_payment",
        "service": "payment_service",
        "action": "charge",
        "compensation": "refund_payment",
        "timeout_seconds": 15
      }
    ]
  }'
```

#### Append an Event to a Stream

```bash
curl -X POST http://localhost:8080/api/v1/events/order_stream_99 \
  -H "Content-Type: application/json" \
  -d '{
    "event_type": "OrderCreated",
    "data": { "customer_id": "user_456", "total": 129.90 },
    "metadata": { "source": "mobile_app" }
  }'
```

## Configuration


Syros can be configured via environment variables or a `config.toml` file.

| Variable | Description | Default |
|----------|-------------|---------|
| `DATABASE_URL` | PostgreSQL connection string | `postgres://syros:syros@localhost:5432/syros` |
| `REDIS_URL` | Redis connection string | `redis://localhost:6379` |
| `SERVER_HOST` | Host interface to bind to | `0.0.0.0` |
| `REST_PORT` | Port for the REST API | `8080` |
| `GRPC_PORT` | Port for the gRPC API | `9090` |
| `WS_PORT` | Port for the WebSocket API | `8081` |
| `JWT_SECRET` | Secret key for JWT generation | `syros-secret-key-change-me` |
| `LOG_LEVEL` | Logging level (info, debug, error) | `info` |

### Available APIs


- **REST API**: `http://localhost:8080` - Complete HTTP interface
- **gRPC API**: `localhost:9090` - High-performance interface
- **WebSocket**: `ws://localhost:8081` - Real-time communication
- **GraphQL**: `http://localhost:8080/graphql` - Flexible queries

## Contributing


1. Fork the project
2. Create a feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## License


This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments


- [Rust]https://www.rust-lang.org/ - Programming language
- [Tokio]https://tokio.rs/ - Async runtime
- [Axum]https://github.com/tokio-rs/axum - Web framework
- [Volo]https://github.com/cloudwego/volo - gRPC framework
- [Redis]https://redis.io/ - Cache and locks
- [PostgreSQL]https://www.postgresql.org/ - Database
- [Prometheus]https://prometheus.io/ - Metrics
- [Grafana]https://grafana.com/ - Dashboards