Ruby gem · jobs + streams · NATS

Cosmo­nats

Background jobs and real-time event streaming for Ruby — one gem, backed by NATS.

No Redis. No DB polling.
No message silently dropped.

Start the journey ↓
scroll to launch

Transmissions · blog

Notes from the crew.

1 transmission received

Why we beamed our background jobs off Redis

Redis is a brilliant key-value store that learned to queue. NATS is a messaging system that learned to store. That difference is the whole reason Cosmonats exists.

Read transmission →

Mission log

Why we built it, one waypoint at a time.

  1. IgnitionWP-01

    Why build another job runner?

    Most Ruby job libraries lean on Redis or Postgres — tools that were never designed to be message brokers. We wanted an engine built for messaging first.

    • Redis: KV first
    • NATS: messaging first
  2. Fuel · NATSWP-02

    A tiny engine with enormous range

    One NATS server replaces your message broker, job queue and KV store — with far less to operate.

    • ~20 MB binary
    • ~10 MB RAM idle
    • disk-backed
  3. Two stages, one rocketWP-03

    Jobs and streams in one gem

    A first-class Job and a first-class Stream, sharing one server, one config, one CLI and one monitoring endpoint.

    • perform_async
    • process_one
    • one cosmo.yml
  4. Time travelWP-04

    Replay any message, from any moment

    Messages persist to disk. Rewind a consumer to the beginning of time, a timestamp, or only new messages.

    • incident recovery
    • bootstrap consumers
    • reproduce bugs
  5. Deep space networkWP-05

    Multi-datacenter, natively

    Clusters and leaf nodes are built into NATS. Spanning regions is a config block, not another product. Lose a node, lose nothing.

    • clustering
    • leaf nodes
    • geo-distribution
  6. No space junkWP-06

    Dedup at the broker, KV built in

    Same-ID messages inside the window are dropped before they reach a worker. A built-in KV store handles locks and rate limits.

    • no uniqueness gems
    • no Redis
    • no Memcached
  7. Mission controlWP-07

    Watch every job in real time

    Mount Cosmo::Web for a live dashboard of jobs, streams, crons and batches — retry, pause and run from one place.

    • jobs
    • streams
    • crons
    • batches
  8. Orbit reachedWP-08

    Battle-tested in production

    Tens of millions of jobs processed and counting. Horizontally scalable, and no message is ever silently dropped.

    • Ruby ≥ 3.1
    • ActiveJob adapter
    • Sentry

Touchdown · taste it

A familiar look. A very different engine.

app/jobs/send_email_job.rbCosmo::Job
class SendEmailJob
  include Cosmo::Job
  options stream: :default, retry: 3, dead: true

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

SendEmailJob.perform_async(123, "welcome")
SendEmailJob.perform_in(1.day, 123, "followup")
app/streams/clicks_processor.rbCosmo::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