> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Sourcegraph is fully relying on Aspect Workflows in their CI/CD pipeline.

> Aspect Workflows helped Sourcegraph accelerate CI builds by 2-3x and cut cloud compute costs by 40%, enhancing performance and efficiency.

export const MarketingPage = () => <div className="marketing-page-marker" style={{
  display: "none"
}} />;

export const Section = ({children, className = "", gray = false, dark = false, id}) => <section id={id} className={`w-full flex justify-center px-4 py-16 md:py-24 ${gray ? "bg-gray-50 dark:bg-zinc-900" : dark ? "bg-zinc-900 dark:bg-zinc-950" : ""} ${className}`}>
    <div className="w-full" style={{
  maxWidth: "1140px"
}}>
      {children}
    </div>
  </section>;

<MarketingPage />

<Section>
  <div className="max-w-3xl mx-auto">
    <div className="case-study-logo">
      <img src="https://mintcdn.com/aspectbuild/x1L7Iep716jCyJVo/images/marketing/customers/sourcegraph-logo.svg?fit=max&auto=format&n=x1L7Iep716jCyJVo&q=85&s=e2662bf928190f5df1b16dade2aefde0" alt="Sourcegraph" noZoom width="186" height="32" data-path="images/marketing/customers/sourcegraph-logo.svg" />
    </div>

    <h1 className="mt-6 text-3xl md:text-4xl font-semibold text-zinc-900 dark:text-white tracking-tight">
      Sourcegraph is fully relying on Aspect Workflows in their CI/CD pipeline.
    </h1>

    <div className="case-study-hero mt-10">
      <img src="https://mintcdn.com/aspectbuild/x1L7Iep716jCyJVo/images/marketing/case-studies/sourcegraph.png?fit=max&auto=format&n=x1L7Iep716jCyJVo&q=85&s=b858b8994e7790de0888dc9a3c69b5f4" alt="" noZoom width="1269" height="826" data-path="images/marketing/case-studies/sourcegraph.png" />
    </div>

    <div className="mt-10 grid grid-cols-2 md:grid-cols-3 gap-6 text-center">
      <div>
        <p className="text-3xl font-semibold text-blue-600 dark:text-blue-400">3.7x</p>
        <p className="mt-1 text-sm text-zinc-500 dark:text-zinc-400">More sub-2min builds</p>
      </div>

      <div>
        <p className="text-3xl font-semibold text-blue-600 dark:text-blue-400">2.4x</p>
        <p className="mt-1 text-sm text-zinc-500 dark:text-zinc-400">Speedup of median build & test</p>
      </div>

      <div>
        <p className="text-3xl font-semibold text-blue-600 dark:text-blue-400">40%</p>
        <p className="mt-1 text-sm text-zinc-500 dark:text-zinc-400">Reduced compute costs</p>
      </div>
    </div>

    <div className="mt-12 space-y-5 text-zinc-600 dark:text-zinc-300 leading-relaxed">
      <p>Sourcegraph is a code intelligence platform known for their AI coding assistant, Cody.</p>

      <p>
        Their software is developed in an Open-Source repository by a large team of engineers, primarily in Go,
        TypeScript, and Rust.
      </p>

      <p>
        They were building \~50 different docker container images, which were not optimized. Optimizing them
        individually was considered less attractive than using a build system that naturally produces correct
        images.
      </p>

      <p>
        The build for the frontend client bundle was non-incremental and rebuilt on every change. This was a
        big pain point and made CI very slow. It was also flaky.
      </p>

      <p>
        Aspect Build Systems is a Bazel product partner and provides a monorepo developer platform called
        Aspect Workflows. By adopting Workflows Sourcegraph was able to resolve these problems, making CI 2-3x
        faster while reducing cloud compute costs by 40%.
      </p>

      <h2 className="mt-10 text-2xl font-semibold text-zinc-900 dark:text-white">History</h2>

      <p>
        An ex-Googler at Sourcegraph wrote a small internal position paper advocating for a move to Bazel, the
        open-source Build & Test tool from Google. His experience in Google's monorepo with a giant Go and
        React app convinced him and the team that "it really works."
      </p>

      <p>
        Sourcegraph was confident in migrating Go and Rust code to build with Bazel, but the frontend code was
        perceived as a risk due to limited resources and the complexity of the code and the migration path.
        This led them to work with Aspect, the author of Bazel's JavaScript rules.
      </p>

      <p>
        Aspect and Sourcegraph began working together in November 2022, as Sourcegraph started their Bazel
        migration journey. On December 2, the setup began:
      </p>

      <pre className="overflow-x-auto rounded-lg bg-zinc-100 dark:bg-zinc-800 p-4 text-sm text-zinc-700 dark:text-zinc-300">
        <code>
          {`commit b1a56385e5659043adc38af53cfd5a131c98b98b
                    Author: Jean-Hadrien Chabran <jh@chabran.fr>
                    Date:   Fri Dec 2 12:57:14 2022 +0100

                      Initial Bazel Setup (#45052)

                      * bazel: initial bazel workspace and rules_js setup
                      * bazel: generate types for schema files
                      * bazel: generate graphql schema file
                      * Fix typo

                      Co-authored-by: Derek Cormier <derek@aspect.dev>`}
        </code>
      </pre>

      <h2 className="mt-10 text-2xl font-semibold text-zinc-900 dark:text-white">Migrating to Bazel</h2>

      <p>
        Bazel adoption is complex. This is partially due to the inherent difficulty in migrating build systems,
        which are deeply integrated with the codebase. Also, Bazel is known for a steep learning curve and
        limited available expertise. Aspect is recognized as the community leader and provides professional
        services. In this case we began with hourly consulting.
      </p>

      <p>
        The work was divided into two phases to mitigate risk. The first was a "Frontend Bazel POC". We agreed
        on the following deliverables:
      </p>

      <ul className="list-disc pl-6 space-y-2">
        <li>Prove that Bazel is a viable and performant build system for Sourcegraph's frontend code.</li>
        <li>Migrate a single React Frontend app to Bazel, using Webpack for bundling.</li>
        <li>Existing Jest tests run under Bazel.</li>
        <li>Demonstrate use of the Aspect CLI to generate BUILD files for TypeScript sources.</li>
        <li>Demonstrate a CI build that is incremental, fast, and robust to network failures.</li>
      </ul>

      <p>
        Following the success of the POC phase, we entered a second phase: "rules\_js Bazel migration", scoped
        to include:
      </p>

      <ul className="list-disc pl-6 space-y-2">
        <li>Fine-grained SASS and Postcss build targets</li>
        <li>Complete @sourcegraph/web bundle</li>
        <li>Mocha integration tests</li>
        <li>Review and optimize Sourcegraph's golang Bazel configuration</li>
        <li>Documentation & Handoff</li>
      </ul>

      <p>
        While Backend engineers were accustomed to maintaining Makefiles, BUILD file generation for JavaScript
        and TypeScript was particularly critical so that frontend engineers don't have a new task of manually
        configuring Bazel as they change source files.
      </p>

      <p>This is integrated into Aspect's CLI tool.</p>

      <h2 className="mt-10 text-2xl font-semibold text-zinc-900 dark:text-white">Aspect Workflows</h2>

      <p>
        Meanwhile, in February 2023, Aspect presented a demo of our turnkey CI/CD solution, Aspect Workflows.
        The first reaction from engineers on the call:
      </p>

      <blockquote className="border-l-4 border-blue-500 pl-4 italic text-zinc-700 dark:text-zinc-200">
        If we showed this to all engineers at Sourcegraph there would be mutiny if we didn't buy it.
      </blockquote>

      <p>
        Aspect provided a free trial of Workflows, giving Sourcegraph time to establish target Key Performance
        Indicators:
      </p>

      <ul className="list-disc pl-6 space-y-2">
        <li>Simple PRs should spend under 2 min in build & test.</li>
        <li>Median (50%ile) build\&test should be 2-3x faster.</li>
        <li>The cost for CI compute should be significantly reduced.</li>
      </ul>

      <p>
        Aspect started performing the install for Workflows in July. As part of the trial, we provided guidance
        to Sourcegraph with graph optimization, non-determinism fixes, and build-without-the-bytes. These all
        improved the codebase, reducing the workload needed for Bazel.
      </p>

      <p>
        By November we were reporting excellent results. Even Quinn, Sourcegraph's CEO "warmed up" to Bazel:
      </p>

      <blockquote className="border-l-4 border-blue-500 pl-4 italic text-zinc-700 dark:text-zinc-200">
        I'm really warming up to Bazel after we started using it for our monorepo at Sourcegraph. I trusted our
        team when they decided to set it up, but only recently did I really become a believer. I trust that I
        can run any build/test steps in a reproducible manner.
        <footer className="mt-2 not-italic text-sm text-zinc-500 dark:text-zinc-400">Quinn Slack, CEO at Sourcegraph</footer>
      </blockquote>

      <p>
        To calculate the return on investment, Sourcegraph ran Aspect Workflows side-by-side with the legacy
        Bazel build. During the period from November 27 to December 18 2023:
      </p>

      <ul className="list-disc pl-6 space-y-2">
        <li>
          3.7 times as many builds ran in under 2 minutes (172 of build\&test jobs (12%) on the legacy
          build, compared to 649 (44%) on Aspect Workflows)
        </li>

        <li>
          Google Compute Engine costs were reduced 40% (December cost for legacy build \$4607, Aspect Workflows
          \$2810)
        </li>

        <li>
          Median (50%ile) build\&test was 2.4x faster (12 minutes on legacy build, 5 minutes on Aspect
          Workflows)
        </li>
      </ul>

      <p>
        Anecdotally, engineers reported getting their fastest build on main with a 1 minute Bazel test of the
        whole repo, thanks to a high cache hit rate. This is the first time engineers on the team have
        experienced such fast builds!
      </p>

      <h2 className="mt-10 text-2xl font-semibold text-zinc-900 dark:text-white">Conclusion</h2>

      <p>
        Aspect Workflows delivered on the promise to make builds significantly faster, while also reducing
        compute costs.
      </p>

      <p>
        Workflows also enabled a couple of key features. The Continuous Delivery pipeline pushes dozens of
        artifacts for each green main build, but only those which were modified. Also, we augmented the
        Buildkite user interface with annotations showing real-time test results from Bazel's Build Events
        stream, so that engineers don't need to wait for the build to complete before learning of a problem.
      </p>

      <p>
        As of March 2024, Sourcegraph is fully relying on Aspect Workflows to run Bazel in their CI/CD
        pipeline.
      </p>
    </div>

    <div className="mt-12">
      <a href="https://cdn.aspect.build/case-studies/Sourcegraph.pdf" target="_blank" rel="noopener noreferrer" className="inline-flex items-center px-6 py-3 rounded-lg bg-blue-600 text-white font-semibold hover:bg-blue-700 transition shadow-sm">
        Download PDF →
      </a>
    </div>
  </div>
</Section>
