How Khan Academy Rewrote Its Backend with Go: A Step‑by‑Step Migration Guide

This article details how Khan Academy transformed its decade‑old Python 2 monolith into a Go‑based, service‑oriented backend, covering the language choice, performance testing, incremental migration steps, architectural benefits, and key lessons learned during the process.

21CTO
21CTO
21CTO
How Khan Academy Rewrote Its Backend with Go: A Step‑by‑Step Migration Guide

Khan Academy migrated its monolithic Python 2 backend to a Go‑based service‑oriented architecture. The following summarizes the motivations, language selection, testing strategy, migration process, and lessons learned.

Overview

By the end of 2019, Khan Academy’s backend, built on a Python 2 monolith that had run reliably for over ten years, needed an upgrade because Python 2 reached end‑of‑life on January 1 2020.

The team evaluated three migration paths:

Upgrade to Python 3, improving performance and language features by 10‑15%.

Migrate to Kotlin for compute‑intensive tasks, offering higher speed and lower server costs.

Migrate to Go, a simple, fast‑compiling language with excellent Google App Engine support and lower memory usage than Kotlin.

After extensive performance testing, they chose Go because it matched Kotlin’s speed while using significantly less memory.

Why Go?

Go is a statically typed compiled language with syntax similar to C. It was designed at Google by Ken Thompson, Rob Pike, and Robert Griesemer. Go offers garbage collection, structural typing, and extremely fast compilation.

From Monolith to Services

In addition to adopting Go, Khan Academy switched to a service‑oriented architecture. Previously, all servers ran the same code and could handle any request. Dedicated services now manage data storage and caching, allowing independent deployment and scaling.

Faster deployments – services can be deployed and tested independently.

Limited impact of failures – issues are isolated to specific services.

Optimized hardware and configuration – each service can use the appropriate instance type and settings.

The new backend continues to run on Google App Engine, using Google Cloud Datastore and other Google Cloud products.

Incremental Migration Strategy

Kevin Dangoor explains that a full rewrite carries high risk, so Khan Academy adopted an incremental approach with four steps:

Monolith control : The GraphQL gateway routes requests to the Python monolith while engineers write Go handlers for the same requests.

Side‑by‑side : Once Go can handle a request, the gateway calls both Python and Go implementations, compares results, logs differences, and returns the Python result to users.

Migration : After extensive testing, traffic is shifted to the Go service; the Python code remains as a fallback.

Removal : Once confidence is high, the Python code is removed entirely.

This process allowed Khan Academy to maintain high availability even as traffic surged during the COVID‑19 pandemic.

Key Principles for a Successful Rewrite

Avoid scope creep – Engineers focus on direct translation from Python to Go without tackling unrelated refactoring.

Parallel testing – Running tests side‑by‑side ensures functional equivalence between old and new services.

Boundary‑less engineering – Engineers work across product domains and service ownership to share knowledge and reduce bottlenecks.

During the migration, usage grew 2.5× in two weeks, and by August 30 2021 the new backend handled 95 % of site traffic, meeting performance targets despite the pandemic‑induced load.

Technical Highlights

The new backend is built on GraphQL Federation , replacing REST with a unified GraphQL gateway that composes schemas from multiple services into a single typed API.

Each service contributes a portion of the overall GraphQL schema; the gateway merges them, allowing seamless queries across services.

During the transition, both the new distributed backend and the old monolith were queried in parallel, with results compared to ensure correctness before fully switching traffic.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

backend-migrationGraphQLKhan Academy
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.