Skip to content
bitsbeamPublic

About

Background and stream processing for Ruby

Topics

Resources

Stars

31 stars

Watchers

2 watching

Forks

Repository files navigation

cosmonats

Background jobs + real-time event streaming for Ruby — unified, in one gem, backed by NATS.
No Redis. No DB polling. Disk-backed, horizontally scalable — no message is ever silently dropped.

logo.svg

Battle-tested in production. Tens of millions of jobs processed and counting.

⚡ Taste it

# Define a job with a familiar look
class SendEmailJob
  include Cosmo::Job
  options stream: :default, retry: 3, dead: true

  def perform(user_id, template)
    EmailService.send(user_id, template)
  end
end

# Enqueue it
SendEmailJob.perform_async(123, "welcome")
SendEmailJob.perform_in(1.day, 123, "followup")
# Process a continuous real-time event stream
class ClicksProcessor
  include Cosmo::Stream
  options stream: :clickstream, batch_size: 100,
          consumer: { subjects: ["events.clicks.>"] }

  def process_one
    Analytics.track(message.data)
    message.ack
  end
end

ClicksProcessor.publish({ user_id: 123, page: "/home" }, subject: "events.clicks.homepage")
bundle exec cosmo -C config/cosmo.yml -c 20         # Run jobs + streams with 20 threads
bundle exec cosmo -C config/cosmo.yml -c 20 jobs    # Jobs only
bundle exec cosmo -C config/cosmo.yml -c 20 streams # Streams only

The same pages live in docs/ for reading on GitHub.

📦 Installation

# Gemfile
gem "cosmonats"

Requirements: Ruby ≥ 3.2, NATS Server ≥ 2.14 with JetStream enabled (install guide)

Spin up NATS instantly with Docker — one command, that's it:

docker run -p 4222:4222 -p 8222:8222 nats:alpine -js

Then follow the quick start.

🎯 Why?

Most background job libraries use Redis or Postgres — tools that were never designed for this. NATS is messaging first, then KV: a ~20 MB binary with disk-backed persistent streams, true horizontal clustering, and clients in every major language. One NATS server replaces your message broker, job queue, and KV store.

Redis/DB-backed NATS/Cosmonats
Persistence In-memory / DB bloat Disk-backed, TB-scale
Scaling Sentinel only / Vertical only True horizontal clustering
Background jobs Yes Yes
Real-time stream No Yes
Zero message loss No Yes
Message replay No Yes
Backpressure No, grow unbounded Yes
Multi-DC Complex setup Native geo-distribution

Read more in the introduction.


Made with ❤️ for Ruby

Blast off Cosmonats! 🚀

About

Background and stream processing for Ruby

Topics

Resources

Stars

31 stars

Watchers

2 watching

Forks

Releases

Contributors

Languages