Introduction

Image of two people kicking the air.
Photo attribution here.

I've become interested in learning how the open-core business model works. In particular, I'm interested in how software engineer Mike Perham runs Sidekiq as a million-dollar business with no employees.

With that in mind, my next deep-dive into open-source codebases will be the free version of the Sidekiq gem. My goal is to not only learn some Ruby coding best practices, but to learn how open-core libraries achieve the dual goal of making the core functionality free, while getting premium customers to pay a monthly fee for extra features.

I've pulled down the latest code from Sidekiq's Github repo, and am currently pointing to commit # 7c41779ad6ea196d75c84a46a1df04405bb6202f. The entry point for this code base (aka the file which gets executed first) is a script named bin/sidekiq, so that's the file I'll inspect first.

The file's code

Relative to the root project directory, the file we'll be reviewing first is bin/sidekiq.

The file is only 38 lines of code long:

#!/usr/bin/env ruby

# Quiet some warnings we see when running in warning mode:
# RUBYOPT=-w bundle exec sidekiq
$TESTING = false

require_relative "../lib/sidekiq/cli"

def integrate_with_systemd
  return unless ENV["NOTIFY_SOCKET"]

  Sidekiq.configure_server do |config|
    config.logger.info "Enabling systemd notification integration"
    require "sidekiq/sd_notify"
    config.on(:startup) do
      Sidekiq::SdNotify.ready
    end
    config.on(:shutdown) do
      Sidekiq::SdNotify.stopping
    end
    Sidekiq.start_watchdog if Sidekiq::SdNotify.watchdog?
  end
end

begin
  cli = Sidekiq::CLI.instance
  cli.parse

  integrate_with_systemd

  cli.run
rescue => e
  raise e if $DEBUG
  warn e.message
  warn e.backtrace.join("\n")
  exit 1
end

We'll probably need more than one post to cover all of this, so let's get started.

Photo Attribution

Title: "Men doing Sidekick"

Description: n/a

Author: photomania

Source: Pixahive

License: CC0 - Free to Use, Attribution Optional