Skip to content

DAMMAK/ChronosCore

Repository files navigation

ChronosCore ⏱️

License .NET Architecture

ChronosCore is a high-performance, distributed, and highly available task scheduler built with C# and .NET 10. It is designed to handle millions of tasks with exactly-once delivery guarantees, automatic failover, and a custom Raft-based consensus protocol.

🚀 Features

  • Distributed Architecture: Horizontally scalable worker nodes with transparent leader election via Raft.
  • Exactly-Once Guarantees: Robust idempotency handling and fencing tokens prevent duplicate task execution.
  • Priority Queuing: Supports 10 levels of task priority with a built-in aging mechanism to prevent task starvation.
  • Cron Schedules: Submit recurring tasks with standard Unix cron expressions.
  • Pluggable Infrastructure:
    • PostgreSQL: Durable persistence for tasks, schedules, and outbox messages using Entity Framework Core.
    • Redis: High-speed priority queues, distributed locking (Redlock), and idempotency storage.
    • RabbitMQ: Message brokering and event distribution powered by MassTransit.
  • Observability: Integrated OpenTelemetry metrics, Serilog structured logging, and health checks.
  • Clean Architecture: Strictly layered design (Domain, Application, Infrastructure, API, Worker).
  • Dual API: Exposes both REST and gRPC endpoints for maximum interoperability.

🏗️ Architecture

ChronosCore enforces a strict Clean Architecture:

  1. Domain: Core entities (ScheduledTask, TaskSchedule, ClusterNode), Value Objects (TaskId, FencingToken, IdempotencyKey), and Domain Events.
  2. Application: CQRS implementation (Commands & Queries) using MediatR, Validation (FluentValidation), and pipeline behaviors (Logging, Performance, Transactions).
  3. Infrastructure: Implementation details (EF Core repositories, Redis queues, RabbitMQ publishers, Raft Consensus, OpenTelemetry).
  4. Worker: Background services (TaskPollingService, ScheduleEvaluatorService, PriorityAgingWorker, TimeoutMonitorService).
  5. API: REST endpoints, gRPC services, API Gateway/Middleware.

🛠️ Tech Stack

  • .NET 10 / C# 14
  • PostgreSQL (Relational & Outbox DB)
  • Redis (Queues, Locks, Caching)
  • RabbitMQ & MassTransit (Messaging)
  • MediatR (CQRS)
  • Entity Framework Core (ORM)
  • OpenTelemetry & Prometheus / Grafana (Observability)
  • Serilog & Seq (Logging)
  • Docker & Docker Compose

💻 Getting Started

Prerequisites

Running Locally

The easiest way to get everything running locally is through Docker Compose. This will spin up the API, Worker, PostgreSQL, Redis, RabbitMQ, Seq, Prometheus, and Grafana.

  1. Clone the repository:

    git clone https://github.com/DAMMAK/ChronosCore.git
    cd ChronosCore
  2. Start the infrastructure and application services:

    docker-compose up -d --build
  3. Access the services:

    • API Swagger UI: http://localhost:5000/swagger
    • Seq Logging: http://localhost:5341
    • RabbitMQ Management: http://localhost:15672 (guest / guest)
    • Prometheus: http://localhost:9090
    • Grafana: http://localhost:3000 (admin / admin)

Building from Source

To build the solution locally using the .NET CLI:

dotnet restore ChronosCore.slnx
dotnet build ChronosCore.slnx

Running Tests

The solution includes comprehensive Unit, Integration, and Chaos tests.

dotnet test ChronosCore.slnx

(Note: Integration tests may require Testcontainers, meaning Docker must be running on your machine).

📚 API Examples

Submit a Task

POST /api/tasks
Content-Type: application/json

{
  "tenantId": "customer-1",
  "taskType": "SendEmail",
  "payload": "{\"to\": \"user@example.com\", \"subject\": \"Hello!\"}",
  "priority": 5,
  "maxRetries": 3,
  "timeoutSeconds": 300
}

Create a Recurring Schedule

POST /api/schedules
Content-Type: application/json

{
  "tenantId": "customer-1",
  "taskType": "DailyReport",
  "payload": "{}",
  "cronExpression": "0 0 * * *"
}

📜 License

This project is licensed under the MIT License.

About

ChronosCore is a high-performance, distributed, and highly available task scheduler built with C# and .NET 10. It is designed to handle millions of tasks with exactly-once delivery guarantees, automatic failover, and a custom Raft-based consensus protocol.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors