# Start from First (/sdks/ruby/how-to/events-store/start-from-first)



## Overview [#overview]

A new consumer joining an Events Store channel usually needs more than what happens next — it needs everything that already happened. `EventStoreStartPosition::START_FROM_FIRST` solves that by replaying the channel's complete stored history before switching to live delivery, so a service can rebuild its state from scratch instead of starting with a blank slate and hoping nothing important was missed.

Under the hood, the broker walks the store from the oldest retained sequence forward, streaming each event to your subscription block in order, then hands off to live delivery of new events without a gap. You don't manage offsets or checkpoints yourself — the start position is set once, at subscription time, via `start_position: KubeMQ::PubSub::EventStoreStartPosition::START_FROM_FIRST`.

**Gotchas:** on a long-lived channel this can mean replaying millions of events before anything new shows up, so it's the wrong choice for a consumer that only cares about "from now on" (use `START_NEW_ONLY` for that). Retention and expiration policies still apply — events already purged by TTL or max-count limits are gone and won't be replayed, so "full history" only means what the store still has.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Ruby SDK installed (`gem install kubemq`)

## Code [#code]

```ruby title="main.rb"
require 'kubemq'

address = ENV.fetch('KUBEMQ_ADDRESS', 'localhost:50000')
channel = 'ruby-events-store.start-from-first'

begin
  client = KubeMQ::PubSubClient.new(address: address, client_id: 'es-first-example')
  puts "Connected to #{address}"

  3.times do |i|
    msg = KubeMQ::PubSub::EventStoreMessage.new(channel: channel, metadata: "stored #{i}", body: "data-#{i}")
    client.send_event_store(msg)
    puts "Pre-stored event #{i}"
  end
  sleep 1

  cancel = KubeMQ::CancellationToken.new

  sub = KubeMQ::PubSub::EventsStoreSubscription.new(
    channel: channel,
    start_position: KubeMQ::PubSub::EventStoreStartPosition::START_FROM_FIRST
  )
  client.subscribe_to_events_store(sub, cancellation_token: cancel, on_error: lambda { |e|
    puts "Error: #{e.message}"
  }) do |event|
    puts "Replayed: #{event.metadata}"
  end
  puts 'Subscribed with START_FROM_FIRST — replaying all stored events'

  sleep 3
rescue KubeMQ::Error => e
  puts "KubeMQ error: #{e.message}"
ensure
  cancel&.cancel
  client&.close
  puts 'Done'
end
```

## How It Works [#how-it-works]

* `START_FROM_FIRST` replays every event ever stored on the channel, then continues with new events.
* Useful for rebuilding state or processing the full event history.
* Review timeouts, channel names, and client IDs before running against shared environments.

## Related [#related]

* [Pattern overview](/learn/events-store/getting-started)
* [Ruby SDK Reference](/sdks/ruby/reference)
* [Start from Last](/sdks/ruby/how-to/events-store/start-from-last)
* [Start New Only](/sdks/ruby/how-to/events-store/start-new-only)
