YouTube Powers 4B Daily Views on 1M Lines of Python, Solomon Says

Scalability at YouTube — Next Day Video

Next Day Video

Massive system scale depends on algorithmic partitioning and loose consistency guarantees rather than premature optimization, allowing rapid Python prototypes and relational databases to survive hypergrowth.

AI-assisted summary of Scalability at YouTube — original source. Check the original for full context.

Source published:

Key ideas

  • YouTube's core infrastructure heavily relies on over a million lines of Python, scaling through a 9-order-of-magnitude increase in view traffic from initial prototypes to handling over 4 billion daily views. (9:33)
  • To escape exorbitant commercial bandwidth costs, YouTube engineered its own custom CDN in two weeks using dense server racks, Lighttpd, and a Python 404 handler, delivering 60 Gbps on its first day. (35:06)
  • YouTube scaled its MySQL database tier by developing Vitess in Go to optimize queries, pool connections, and route traffic via custom RPCs, dispelling the belief that relational databases cannot scale. (29:47)
  • Replacing an early HTTP and pickle-based internal RPC layer with direct socket RPCs cut YouTube's global CPU usage by roughly 8%, while custom BSON serializers outperformed off-the-shelf alternatives by 10x to 15x. (26:47)

Detailed notes

## Background Published on YouTube by Next Day Video on March 11, 2012, this conference session features YouTube Developer Advocate Shannon -jj Behrens and foundational YouTube engineer Mike Solomon at PyCon. According to the video description, the talk offers a rare glimpse into the architectural heart of YouTube—one of the largest web platforms in the world—and explores how it scales its massive infrastructure using Python.

## TL;DR Following an opening by Shannon -jj Behrens on YouTube's operational footprint and API integrations, early engineer Mike Solomon outlines the architectural philosophies that allowed YouTube to scale its view traffic across nine orders of magnitude. Solomon advocates for starting simple with loose behavioral guarantees, using techniques like divide and conquer, approximate correctness, and cache jitter to maintain system stability. He reviews YouTube's core technology choices—including Apache, the custom Wise Guy FastCGI container, MySQL paired with Vitess, Spitfire templating, and an in-house CDN built in two weeks with Lighttpd—while urging engineers to prioritize clean data contracts and macro-level architecture over micro-optimizations.

## Atmosphere & style The talk opens with playful tech banter and developer-advocate humor before shifting into the dry, candid reflections of an engineer who built critical systems from the ground up. Mike Solomon presents with unpretentious authenticity, treating staggering web-scale challenges with casual pragmatism and deadpan wit. Watching the session feels like sitting in on an intimate post-mortem with a veteran hacker who openly shares past architectural blunders and war stories to demystify distributed systems.

## Bulletin - [09:33](https://www.youtube.com/watch?v=G-lGCC4KKok&t=573s) YouTube's core infrastructure heavily relies on over a million lines of Python, scaling through a 9-order-of-magnitude increase in view traffic from initial prototypes to handling over 4 billion daily views. - [35:06](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2106s) To escape exorbitant commercial bandwidth costs, YouTube engineered its own custom CDN in two weeks using dense server racks, Lighttpd, and a Python 404 handler, delivering 60 Gbps on its first day. - [29:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1787s) YouTube scaled its MySQL database tier by developing Vitess in Go to optimize queries, pool connections, and route traffic via custom RPCs, dispelling the belief that relational databases cannot scale. - [26:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1607s) Replacing an early HTTP and pickle-based internal RPC layer with direct socket RPCs cut YouTube's global CPU usage by roughly 8%, while custom BSON serializers outperformed off-the-shelf alternatives by 10x to 15x.

## Key takeaways - [00:01](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1s) YouTube serves more than 4 billion video views per day with over 60 hours of video uploaded every minute across 350 million enabled devices. - [09:33](https://www.youtube.com/watch?v=G-lGCC4KKok&t=573s) Foundational subsystems including transcoding, indexing, search, streaming, and CDN logic originated as simple Python prototypes that stayed in production long term. - [13:31](https://www.youtube.com/watch?v=G-lGCC4KKok&t=811s) The guiding architectural philosophy is to prioritize simplicity and loose guarantees early to avoid painting system designs into unworkable corners. - [14:50](https://www.youtube.com/watch?v=G-lGCC4KKok&t=890s) Approximate correctness allows distributed systems to avoid expensive global transactions when data inconsistencies are imperceptible to users. - [18:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1094s) Injecting artificial randomness (jitter) into cache expiration windows prevents self-synchronization and devastating thundering-herd effects on backend services. - [18:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1094s) Updating view counters via infrequent batching and pseudo-random increments avoids overwhelming transactional databases with single-increment writes. - [22:04](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1324s) Failing to define explicit typed data contracts between architectural layers—such as passing generic dictionaries between serving and templating tiers—generates massive technical debt. - [24:26](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1466s) Raw code execution speed does not equal system scalability; structural partitioning, boundary management, and clean algorithmic design provide far greater returns. - [24:26](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1466s) Application runtimes in Python are frequently dominated by payload serialization, deserialization, and garbage collection rather than core business logic. - [26:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1607s) Writing straightforward, easily searchable code without heavy metaprogramming or magic keeps execution fast and systems maintainable. - [26:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1607s) YouTube operates on a synchronous FastCGI servlet container called Wise Guy behind standard Apache web servers rather than an asynchronous event loop. - [29:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1787s) Linux provides critical low-level observability tools like strace and tcpdump that expose system resource usage regardless of application code quality. - [29:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1787s) Apache ZooKeeper serves as YouTube's central distributed lock manager and configuration management system. - [33:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1994s) YouTube organizes Python code primarily using namespaces and treating classes as lightweight C-style structs rather than deep object-oriented hierarchies. - [37:40](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2260s) Live schema and infrastructure migrations are safely executed by incrementally canarying read traffic while validating writes through extensive pre-cutover simulations.

## Detailed walkthrough ### [00:01](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1s) Introduction and YouTube Platform Scale

Shannon -jj Behrens opens the session at PyCon, jokingly introducing himself as a YouTube Developer Advocate, or a self-described “booth babe,” before playfully observing that the shtick isn't working because the audience has far too many men. He compares his opening remarks to the pre-roll advertisement viewers have to sit through before watching a Shakira video, explaining that just as Shakira needs to get paid, he is there to deliver the commercial upfront. His objective is to discuss how Python-based startups can leverage the YouTube platform to grow their businesses.

Behrens presents several high-level figures illustrating the operational footprint and growth of YouTube:

- YouTube serves more than 4 billion video views per day. - Every single minute, users upload over 60 hours of video content. He jokes that in the early days, the platform only took in around 39 hours per minute and could fit everything onto a single hard drive before needing to upgrade to RAID. - Across the globe, more than 350 million devices are YouTube-enabled. - Financially, YouTube's revenue more than doubled in 2010, establishing it as a profitable enterprise.

[01:16](https://www.youtube.com/watch?v=G-lGCC4KKok&t=76s) Four Strategies for Startups on YouTube

To help developers and founders take advantage of this reach, Behrens outlines four core strategic approaches startups can employ:

1. **Creating viral video content:** Producing engaging media that catches on virally to ride organic distribution waves. 2. **Engaging with the community:** Creating substantive content to cultivate and interact directly with an audience. 3. **Integrating with YouTube APIs:** Embedding YouTube functionalities directly into existing products. 4. **Innovating with new applications:** Building entirely novel applications powered by YouTube's backend and frontend APIs.

[01:56](https://www.youtube.com/watch?v=G-lGCC4KKok&t=116s) Viral Marketing and Community Engagement Examples

Illustrating the viral media route, Behrens plays an elaborate tech-rap music video featuring lyrics about the "blogosphere," the "Twitterverse," dominating the online scene, and dreaming of becoming the next Zuckerberg. After restarting the clip so the room can hear the audio clearly, he reveals that the production was actually an organic viral commercial for a VoIP provider. As Behrens points out, tech-minded people who enjoy and share the humorous video are precisely the demographic most likely to purchase a VoIP service, proving that a well-crafted viral campaign can substitute for expensive advertising budgets: “And so you know, you make this video, it goes viral, and then suddenly you don't have to pay for marketing cuz it's free.”

Switching to the second strategy—community engagement—Behrens showcases a video produced by a boutique skateboard company. Originally, the founders spent heavily on conventional social networking ads to reach skateboarders, with minimal return. They changed tactics completely: they began filming skateboarding videos, uploading them directly to YouTube, and actively answering questions in the comments whenever viewers asked about their boards. Behrens recounts speaking with the founders directly, noting: “And I talked to these guys and they're like, 'Yeah, we're not doing anything else. This worked better than, you know, spending money on anything else. This is all we're doing from now on.'” He highlights that unlike television, which remains a one-way broadcast, YouTube functions as a conversational medium where companies can directly converse with their customer base.

[06:48](https://www.youtube.com/watch?v=G-lGCC4KKok&t=408s) API Integration and Custom Innovation

Behrens covers the third strategy—product integration—by presenting YouTube Direct, an open-source App Engine application. News organizations and content publishers embed YouTube Direct into their websites to let users submit user-generated video directly to the publisher's platform, building deeper community involvement.

```mermaid flowchart TD accTitle: YouTube Integration and Innovation Paths accDescr: Diagram showing how products integrate via YouTube Direct or innovate using custom player and data APIs.

subgraph Integration["YouTube Direct (App Engine)"] A["User Video Submission"] --> B["Embedded Web Widget"] B --> C["News / Media Site Backend"] end

subgraph Innovation["Custom Client Application"] D["YouTube Data API"] --> E["App Interface (e.g. History of Jazz)"] F["Customized Player API"] --> E E --> G["Monetization (Paid App & iTunes Links)"] end ```

For the fourth strategy—innovating entirely new software—he showcases *The History of Jazz*, an interactive iPad application designed like a digital coffee-table book. The application uses YouTube's APIs to stream historical performances alongside educational narratives. The developers monetize through dual revenue streams: upfront app purchases and integrated iTunes links for the featured tracks.

[08:01](https://www.youtube.com/watch?v=G-lGCC4KKok&t=481s) YouTube APIs and Python Implementation

Behrens breaks down YouTube's developer surface into two distinct API tiers:

- **Google Data APIs (Backend):** Built around RESTful principles utilizing Atom and JSON formats. Behrens jokes that he attempted to convince the team to adopt CORBA instead, but was turned down. Client libraries are provided for Python as well as other platforms. The Data API allows applications to handle video uploads, searches, ratings, comments, and playlist management. By using OAuth 2.0 authentication, third-party apps can perform these actions directly on behalf of authenticated user accounts. - **Player APIs (Frontend):** Accessible via JavaScript and ActionScript, allowing developers to manipulate playback, tweak operational player parameters, or embed a completely chromeless version of the video player for bespoke user experiences.

Demonstrating the developer workflow, Behrens displays a Python snippet showing how simple it is to pull data from YouTube:

```python import gdata.youtube import gdata.youtube.service

yt_service = gdata.youtube.service.YouTubeService() query = gdata.youtube.service.YouTubeVideoQuery() query.vq = 'python' query.orderby = 'viewCount' feed = yt_service.YouTubeVideoQuery(query)

for entry in feed.entry: print(entry.media.title.text) print(entry.GetSwfUrl()) ```

He concludes by directing developers to the `@YouTubeDev` Twitter handle, his blog at `gx.blogspot.com`, and reminding the audience to consult the Terms of Service and monetization guidelines before introducing the featured speaker.

[09:33](https://www.youtube.com/watch?v=G-lGCC4KKok&t=573s) Mike Solomon on YouTube's Scale and Python Foundation

Behrens hands the presentation over to Mike Solomon, introducing him as the first employee at YouTube and the engineer who was originally responsible for ensuring every single video played when a user clicked the play button.

Solomon takes the stage, joking about running the slides from the back, and reflects on the challenge of compressing seven years of rapid architectural evolution into a single 30-minute conference presentation. He clarifies that while the talk targets scalability principles applicable across multiple programming languages, YouTube's core identity remains tied to Python.

Over his tenure, Solomon designed and built several foundational components of YouTube's infrastructure: - Core server architecture - Video indexing pipelines - Video transcoding services - Full-text search infrastructure - Internal Content Delivery Network (CDN) - Video delivery and streaming mechanisms - Image serving systems

He explains that nearly all of these subsystems began as rapid Python prototypes, and those prototypes proved resilient enough to remain in active production far longer than anticipated. Even as the company scaled, Python maintained its dominance across the codebase. Solomon reports: “And at last count there was like over a million lines of Python running running this thing, so lest anybody doubt, we actually really do use Python in a very, very big way.” Every user watching a video triggers execution across layers of Python services.

Solomon outlines the thesis for the remainder of his lecture: distinguishing between the often-confused concepts of *scalability* and *efficiency*, both of which become critical when a system expands beyond normal limits. To contextualize the engineering hurdles the team tackled, Solomon notes that during his time at YouTube, video view traffic multiplied by nine orders of magnitude.

[12:10](https://www.youtube.com/watch?v=G-lGCC4KKok&t=730s) The Core Ethos: Start Simple, Add Complexity Later

Scalability spans multiple axes—how code is written, executed, and maintained over time. When tasked with designing a new system or addressing a problem space, the foundational instinct should always be simplicity. Although real-world engineering is full of intricate problems, the initial version does not need to be complicated. Mike Solomon emphasizes that systems evolve gradually: many YouTube systems began as a single Python file before growing into sprawling ecosystems over many years. A truly scalable system operates smoothly in the background without getting in the engineer's way, rather than relying on buzzwords.

> “I mean the if I could if I could give you one word about scalable systems I think the word would be simple and every time I'm trying to build something new or look at at a way to solve a problem I'm looking for the most simple thing that will actually you know address the problem space and um you know thing there are lots of complicated problems but the first crack doesn't have to be that complicated the complexity will come over time naturally you can start you don't have to help it out at the beginning” — Mike Solomon

[13:31](https://www.youtube.com/watch?v=G-lGCC4KKok&t=811s) The “Tao of YouTube” and Preserving Flexibility

The guiding philosophy—the "Tao of YouTube"—centers on choosing the simplest solution possible with the loosest practical guarantees. Over-specifying a system or attempting to guarantee every behavior immediately paints an architecture into a corner, introducing artificial complexity and eliminating escape hatches when assumptions fail. In design reviews, engineers are encouraged to ask how a feature can iterate and how data will genuinely be used, because early assumptions rarely hold over time. Solomon jokes that YouTube originally started out as a video dating site; had the team rigidified the architecture around that initial premise, the platform would not have survived to become what it is today.

> “The reason that you want all these things is because you need flexibility to solve problems and the minute you overs specify something you paint yourself into a corner you're not going to be able to to make those guarantees and you you know the your problem becomes automatically complex when you're trying to guarantee everything and you you leave yourself no way out” — Mike Solomon

```mermaid flowchart TD accTitle: System Scalability Evolution Loop accDescr: Diagram illustrating how systems start with simple files and loose guarantees, iterate through dynamic changes, and scale out safely.

subgraph Design["Design Philosophy"] A["Single Python File / Minimal Design"] --> B["Loose Guarantees & Maximum Flexibility"] end

subgraph Growth["Evolutionary Scaling"] B --> C{"Work Partitioning"} C -->|"Divide & Conquer"| D["Stateless Web Tier"] C -->|"Sharding"| E["Database Shards"] end

subgraph Techniques["Operational Tricks"] D --> F["Dynamic Python Modifications"] E --> G["Approximate Correctness & Jitter"] end ```

[14:50](https://www.youtube.com/watch?v=G-lGCC4KKok&t=890s) Divide and Conquer, Dynamic Python, and Approximate Correctness

The cornerstone technique of scalability is divide and conquer: partitioning work and determining execution boundaries. In the web tier, this manifests as spraying requests across a pool of independent, largely identical web servers. In the storage layer, it underpins database sharding—subdividing datasets and minimizing communication between partitions. Because Python is entirely dynamic, even an imperfect early API can be rescued later: engineers can stub, modify, or decorate their way around edge cases using quick adjustments rather than rewriting foundational layers.

Another essential technique is approximate correctness. Solomon references a basic law of systems: the state of the system is simply whatever it is reported to be. If an inconsistency is invisible to a user, it functionally does not exist. For example, if a user posts a comment, another viewer across the world does not need to see it within 300 to 400 milliseconds; the author, however, expects to see their own comment immediately. Rather than forcing expensive worldwide transactions, the platform cheats locally for the author while allowing eventual consistency across the rest of the globe.

> “Approximate correctness is another one of my favorite techniques um this is sort of a you know one of the first rules of of systematics is the state of the system is that what it which is reported to be so if you can't tell that that your system is fundamentally skewing and and inconsistent as from the user perspective then it's not” — Mike Solomon

- Divide and conquer applies equally to horizontal stateless web tiers and relational database sharding strategies. - Python's dynamic runtime allows teams to modify, decorate, and stub out problematic API calls in production without heavy redesigns. - Tailoring consistency models to specific sub-features avoids global transactional overhead (e.g., loose eventual consistency for video comments versus strict persistence for paid movie rentals).

[18:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1094s) System Entropy, Jitter, and the Value of Cheating

Distributed applications behave like chaotic weather systems where minor delays cause cascading issues. If identical cache expirations are configured across popular videos—for instance, caching a daily top video for an exact 24-hour window—every server will observe the expiration at the identical moment and stampede the backend in a self-inflicted thundering herd. YouTube combats this by introducing jitter: setting a target cache lifetime of 24 hours but randomly scattering the expiration between 18 and 30 hours. Unchecked distributed systems naturally tend to self-synchronize—such as when multiple threads block on a single slow disk—removing entropy from the system until an artificial injection of randomness (jitter) breaks the lockstep.

Solomon also highlights the engineering value of deliberate "cheating," echoing advice from his former boss:

> “My old boss told me that the fastest function call is the one that never happens and I have to I have to agree” — Mike Solomon

A concrete example is managing monotonically increasing counters, such as video views or profile view counters. Executing an ACID transaction on every single increment is prohibitively expensive. Instead, the application runs transactions infrequently, batching updates by a pseudo-random amount. As long as the count noticeably shifts from odd to even, users perceive the counter as dynamic and real without imposing crushing load on underlying transactional databases.

[21:07](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1267s) Data-Centric Architecture and Scalable Components

Well-designed scalable components are identifiable by clean inputs, distinct outputs, and well-managed contracts. As YouTube expanded and engineering headcounts grew, defining tight data structures became far more critical than relying on written documentation. When a data object clearly specifies what enters and leaves a function, engineers can inspect the object directly to understand the system state before and after transformations. While Solomon admits the YouTube codebase had not always been flawless at enforcing rigorous data boundaries everywhere, establishing predictable data flows remains vital for debugging, setting operational expectations, and keeping large architectures comprehensible.

[22:04](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1324s) Drawing Clean Boundaries: RPCs and Data Contracts

Mike Solomon reflects on how systems inevitably evolve toward Remote Procedure Calls (RPCs), particularly within a Python environment. Because Python is dynamically typed and inherently loose, the internal structure of an application depends entirely on programmer discipline. Establishing firm conventions early on is critical, but when conventions break down, introducing a hard RPC boundary acts as a firewall. Solomon illustrates this simple interface contract: “I will give you an integer and you should give me a Boolean back and that's it you know that that is that is a sum total of our conversation.” Clear component boundaries allow services to be swapped in and out over time. Initial versions might last only a month or six months before needing replacement, whether that means rewriting a Python component in C, altering it, or discarding it altogether.

As engineering teams scale, nobody can grasp the entirety of the codebase at once. Systems must be partitioned into well-defined subcomponents with clear domains—such as separating video transcoding from video search or database infrastructure. However, these distinct systems still need to share data, making explicit data specifications vital. Solomon confesses what he considers his own worst architectural mistake: defining the boundary between the serving layer and the templating layer as a generic dictionary.

```mermaid flowchart LR accTitle: Python Serving Layer to Template Layer Interface accDescr: Diagram illustrating how the serving layer passed a bloated dictionary to the template layer instead of a typed data object.

subgraph ProblematicDesign["Untyped Interface (The 'Greatest Sin')"] direction LR S["Serving Layer"] -->|"Dict with 100s of keys"| T["Template Layer"] end

subgraph PreferredDesign["Intended Typed Interface"] direction LR S2["Serving Layer"] -->|"WatchPage Object"| T2["Template Layer"] end ```

He explains that spending just ten minutes creating an explicit data object would have avoided years of technical debt: “The like the greatest sin I think I ever committed was the interface between the the serve layer and the template layer is a dictionary this is this is a phenomenally bad idea you you should not do this.” Instead of having a clean `WatchPage` object encapsulating video details, comments, and related videos, the application ended up passing around an untyped dictionary containing hundreds of arbitrary attributes.

- **Component Lifespans:** Early iterations often survive only one to six months; boundaries give engineers the flexibility to rewrite, tune, or discard components as performance needs dictate. - **Cognitive Load:** Well-defined boundaries prevent engineers from needing complete codebase knowledge to work on subsystems like search or transcoding. - **The Dictionary Antipattern:** Using raw dictionaries across major architectural tiers obscures data dependencies and makes maintainability significantly harder over time.

---

[24:26](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1466s) Algorithmic Focus, Python Efficiency, and Profiling Pitfalls

Solomon reiterates that raw execution efficiency does not correlate with scalability, noting that cramming logic into a single monolithic C process might be mechanically efficient but fails entirely when human developer time is valued. The biggest operational gains come from architectural decisions at the macro level—determining whether a routine belongs inline, behind an RPC, or tucked into a subpackage for future migration. Furthermore, focusing on algorithmic complexity yields massive rewards. Python excels here because the barrier to implementing sound algorithms is remarkably low. Modules like `bisect` allow developers to take unsophisticated, accidentally sorted lists, perform fast operations, serialize them, and read them back in at orders-of-magnitude lower computational cost without reinventing basic data structures in C.

Efficiency in Python also requires careful profiling and measurement, which Solomon compares to reading tea leaves. Intuitive guesses about bottlenecks are frequently wrong due to hidden runtime overheads, such as garbage collection costs. A massive portion of YouTube’s application runtime is consumed simply serializing and deserializing data. Profiling these serializers requires realistic input; Solomon warns that testing a serializer with simple integers yields completely deceptive numbers if production actually passes 4KB Unicode blobs through the system.

- **Efficiency vs. Scalability:** Squeezing maximum speed out of a single process often hurts scalability; architectural partitioning and macro-level design must take priority over micro-optimizations. - **Algorithmic Wins in Python:** Tools like the built-in `bisect` module provide high-order performance improvements with negligible engineering overhead compared to custom C implementations. - **Garbage Collection and Serialization:** Application runtimes are frequently dominated by payload serialization and memory management rather than pure business logic. - **Benchmarking Real Payloads:** Synthetic benchmark data (such as bags of integers) fails to capture production behavior, where large Unicode payloads expose serializer inefficiencies.

---

[26:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1607s) Keeping Code “Dumb”: Libraries, Custom Frameworks, and Apache

Achieving efficiency in Python is often about knowing what *not* to do. Solomon cautions that heavy metaprogramming and dynamic runtime tricks directly increase execution costs: “Dumb tends to turn out to be fast so this is something that we also we use a lot and it also it has other side effects too Dumber code is easier to grep for is easier to maintain.” Straightforward, readable code benefits engineers who rely on traditional terminal workflows using tools like Emacs and `grep`. Highly magical codebases obscure what is actually happening under the hood.

Solomon details the specific networking, serving, and templating components that power YouTube:

| Component / Layer | Technology Used | Architecture and Operational Role | |:--- |:--- |:--- | | **HTTP Client Library** | `cURL` (`pycURL`) | Chosen because most client-side HTTP libraries are poor; `cURL` is complex to integrate with, but provides outstanding baseline performance. | | **Internal RPC Protocol** | Direct socket RPC (custom) | Replaced an earlier HTTP/pickle-based transport; dropping HTTP enveloping and adopting direct sockets lowered YouTube's global CPU usage by roughly 8%. | | **Application Container** | **Wise Guy** | A FastCGI servlet container built with C and preforked process management. YouTube operates on a blocking, synchronous model rather than an asynchronous event loop. | | **Web Server** | **Apache HTTP Server** | Every incoming request to YouTube routes through Apache at some stage. Solomon highlights Apache as rock-solid, dispelling myths that high-scale sites must replace it. | | **Templating Engine** | **Spitfire** | Similar to Cheetah; compiles templates using an internal Abstract Syntax Tree (AST) to apply code transformations and runtime optimizations. |

Solomon stresses that engineers must evaluate their data formats carefully, explicitly warning against Python's default serialization: “Don't use pickle for things if it's going if it's I don't think I should have to tell you this but yeah don't use pickle we did it's not a good choice.”

---

[29:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1787s) Core Infrastructure: Linux, MySQL, Vitess, and ZooKeeper

Solomon details YouTube's underlying infrastructure stack, highlighting Linux as the ideal operating system for distributed engineering. Having worked previously on BSD and Windows at Microsoft, he favors Linux for its observability “manholes.” Even when an application is poorly written, its underlying system resource consumption remains fully discoverable using standard utilities such as `strace` and `tcpdump`.

MySQL serves as YouTube’s primary operational database. Every video watched on the platform pulls substantial data from MySQL instances, functioning alternately as a traditional relational store or simply as a high-throughput blob store. Solomon dismisses broad claims that relational databases cannot operate at web scale: “Anybody who sort of blind you tell blindly tells you that MySQL doesn't scale or doesn't do something probably has not considered exactly how to solve the problem.”

To scale their database tier, YouTube developed **Vitess**, a Go-based front end and proxy for MySQL that Solomon works on directly. Vitess sits in front of the database clusters, dynamically rewriting and optimizing queries, performing connection pooling and proxying, and serving every incoming database request via custom RPCs. Finally, Solomon highlights **Apache ZooKeeper**, which he half-jokingly calls the lone piece of Java software that makes him think Java might be redeemable. YouTube uses ZooKeeper as a distributed lock manager and highly reliable filesystem-like store to manage system-wide configuration.

- **System Observability:** Linux provides low-level diagnostics (`strace`, `tcpdump`) that allow engineers to inspect exactly how running code interacts with the kernel and network. - **MySQL Utilization:** Used flexibly across YouTube as both a relational database and a blob storage engine depending on the workload and data model. - **Vitess:** Built in Go to handle query optimization, traffic routing, and connection scaling upstream of MySQL instances; powers YouTube's database traffic. - **Apache ZooKeeper:** Provides robust distributed coordination, locking, and configuration management across YouTube's infrastructure.

[32:04](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1924s) Engineering Productivity and the Pet Peeve of Trivial Documentation

Mike Solomon shifts from database technologies to productivity, remarking that with complex tools, “you have to actually read the manual” rather than blindly tossing things in. When it comes to engineering productivity, Solomon admits the concepts are somewhat nebulous and that he believes far more in guiding philosophy than rigid doctrine. While teams preach simplicity, he acknowledges that defining it in the abstract is impossible: “All right, make it simple—what does that mean? I don’t know, but I’ll know it when I see it.” If an engineer’s first pull request arrives with thousands of lines spread across dozens of files, Solomon argues there was almost certainly a simpler path forward. His core rule for developers is to build a minimal prototype, get it functioning, and iterate from there.

Turning to developer ergonomics, Solomon vents about his personal pet peeve in codebases: redundant documentation comments that restate the obvious without adding context. When developers define an argument like `video_id` and follow it with a docstring reading `video_id: this is the video ID`, it wastes valuable vertical screen space without providing any information. On a small laptop screen, losing several lines of header space to tautological descriptions is deeply frustrating, and he urges developers to abandon the habit.

- Code reviews should prioritize minimal, simple implementations that can be iterated upon rather than massive, sprawling initial diffs. - Avoid low-value comments that merely mirror variable names, preserving vertical screen real estate for substantive code logic.

---

[33:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1994s) Code Organization, Python Conventions, and the "Code Bonsai"

Explaining YouTube’s architectural conventions, Solomon notes that the engineering team rarely relies on heavy object-oriented programming. Instead, they organize code around namespaces and treat classes primarily like C structs to pass data around, keeping operations in module-level functions. Solomon recalls that in early Python versions (and at his previous company), module-level functions were significantly faster than method calls on objects. While Python 2.6 introduced improved caching that diminished that performance delta, the functional, namespace-driven style remained deeply ingrained in the YouTube codebase.

Wrapping up his prepared remarks, Solomon reflects on how he approaches software engineering advice. Rather than blindly copying specific technical implementations, he focuses on understanding the mindset behind them: “Whenever I talk to some really smart dude, I always feel like what motivated this guy to make these decisions—that’s more what helps me make good decisions than trying to actually repeat what he did.” He closes with his concept of the "Code Bonsai," an idealistic metaphor he pitched for code tree maintenance. While he envisioned a perfectly pruned, beautiful bonsai tree, he jokes that the reality of the YouTube code tree is far messier and wilder than any idyllic slide deck could capture.

```mermaid flowchart TD accTitle: YouTube Early Code Organization Pattern accDescr: Diagram illustrating how YouTube engineers structured code using data classes and module-level functions rather than deep object-oriented class hierarchies.

subgraph DataStructures["Data Layer"] DS["Data Container<br>(Class used as a C-style Struct)"] end

subgraph LogicLayer["Namespace & Logic"] F1["Module-Level Function A"] F2["Module-Level Function B"] end

DS -->|"passed into"| F1 DS -->|"passed into"| F2 ```

- Classes are predominantly used as lightweight data holders rather than polymorphic object-oriented hierarchies. - Historically, module-level function execution was notably faster in Python than bound method lookups. - The "Code Bonsai" represents an aspirational vision of codebases being intentionally manicured, even if real-world hypergrowth causes trees to sprawl.

---

[35:06](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2106s) Building the In-House YouTube Video CDN in Two Weeks

Opening the floor to questions, an audience member asks about the architecture and technologies powering YouTube’s CDN. Solomon explains that YouTube initially outsourced video and image delivery to third-party commercial CDNs. However, paying bandwidth bills for third-party CDNs quickly proved to be "psychotically expensive," making an in-house build inevitable once traffic reached scale.

To replace the commercial vendors, YouTube relied on simple tools paired with experienced hardware engineering. A hardware engineer assembled high-density server racks connected to high-capacity network switches. For the software layer, they deployed Lighttpd (Lighty) and customized its 404 error handler with a lightweight Python script that resolved the backend location of any requested video file that missed the local cache. The solution was remarkably fast to ship: “That took two weeks, and on its first day served 60 gigabits.” Solomon emphasizes that massive throughput does not always demand complex infrastructure; basic, reliable building blocks can accomplish extraordinary feats.

```mermaid flowchart LR accTitle: YouTube Original In-House CDN Routing Flow accDescr: Flow diagram showing how Lighttpd served cached video requests or invoked a Python 404 handler to fetch missing videos.

User["Client Request"] --> Switch["Rack Network Switch"] Switch --> Lighty["Lighttpd Edge Server"] Lighty -->|"Cache Hit"| Serve["Stream Video to User"] Lighty -->|"404 Cache Miss"| PyHandler["Python 404 Handler"] PyHandler -->|"Resolve & Fetch"| Origin["Storage Backend / Cluster"] Origin --> Serve ```

- Third-party CDN hosting was abandoned because bandwidth costs scaled prohibitively fast. - The initial custom CDN was constructed in two weeks using dense rack hardware, robust switching, and Lighttpd. - Cache misses were managed by routing Lighttpd 404 errors to a custom Python lookup script. - The internal CDN handled 60 Gbps on its very first day of production traffic.

---

[36:20](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2180s) Protocol Buffers, High-Speed BSON, and Vitess Serialization

An attendee from a company serving around 80 million users asks about serialization performance, noting that their team abandoned Python Protocol Buffers due to severe serialization overhead and wrote a custom C-based library called Palm. Solomon agrees that Protocol Buffers in Python have historically struggled with performance, remarking, “The question was loosely, 'We’re trying to use Protocol Buffers—are Protocol Buffers actually fast?' The answer is kind of no, but they’re going to get better.”

Solomon highlights that measuring serialization bottlenecks led YouTube down a similar optimization path. Rather than relying on standard Protocol Buffers or default BSON libraries, YouTube built a specialized, highly optimized BSON implementation tailored to their pipelines. Solomon reveals that their custom engine runs roughly 10 to 15 times faster than standard off-the-shelf BSON libraries. He adds that YouTube is contributing this work back to the community by open-sourcing the implementation as part of the Vitess project.

- Python Protocol Buffer libraries suffered from significant CPU overhead during serialization and deserialization. - YouTube authored an in-house BSON parser that outperformed available stock libraries by 10x to 15x. - The high-performance BSON serialization library was designated for open-source release within the Vitess project.

---

[37:40](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2260s) Migrating Live Production Systems Under Heavy Load

The final question addresses the challenge of implementing new features or migrating data models on an actively running system that already receives massive production traffic. Solomon characterizes the dilemma as figuring out “how do you change the wheels while the car is running.”

Drawing from his extensive experience with large-scale data migrations, Solomon explains that while every application has unique constraints, YouTube relies on incremental traffic splitting and targeted simulations. When executing a major database or feature migration, engineers gradually route a small percentage of read traffic to the new data path to evaluate behavior under real-world conditions. Write traffic, however, carries much higher risk: engineers must run thorough simulations in advance, ensure confidence in data consistency, and execute the switchover. Solomon notes with a grin that while there is always an element of crossing your fingers, disciplined traffic routing and simulations have kept YouTube free of major migration catastrophes.

- Large-scale schema and architectural migrations are conducted using incremental percentage-based canary routing on read traffic. - Write migrations rely heavily on simulated workloads prior to cutover to prevent data corruption under load. - Incremental read-splitting minimizes blast radius and validates data path latency before systems commit entirely to new backends.

## Notable quotes > [33:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1994s) Whenever I talk to some really smart dude, I always feel like what motivated this guy to make these decisions—that’s more what helps me make good decisions than trying to actually repeat what he did. — Mike Solomon

> [12:10](https://www.youtube.com/watch?v=G-lGCC4KKok&t=730s) if I could give you one word about scalable systems I think the word would be simple — Mike Solomon

## Mentioned Shannon -jj Behrens, Mike Solomon, YouTube, PyCon, Google Data APIs, YouTube Direct, App Engine, The History of Jazz, OAuth 2.0, Python, C, Go, cURL, pycURL, Wise Guy, Apache HTTP Server, Spitfire, Cheetah, Linux, MySQL, Vitess, Apache ZooKeeper, Lighttpd, Protocol Buffers, BSON, Palm

## Video description Shannon -jj Behrens, Mike Solomon This talk covers scalability at YouTube. It's given by one of the original engineers at YouTube, Mike Solomon. It's a rare glimpse into the heart of YouTube which is one of the largest websites in the world, and on

[Source](https://www.youtube.com/watch?v=G-lGCC4KKok)

中文简报

所罗门称YouTube以百万行Python代码支撑每日40亿次观看 大规模系统的扩展依赖算法分区和宽松的一致性保证,而非过早优化,这使得快速的Python原型和关系型数据库在超高速增长中得以存续。 在香农·-jj·贝伦斯(Shannon -jj Behrens)就YouTube的运维规模和API集成发表开场介绍后,早期工程师迈克·所罗门(Mike Solomon)概述了让YouTube观看流量实现9个数量级增长的架构哲学。所罗门提倡从具备宽松行为保证的简单方案入手,利用分治法、近似正确性和缓存抖动等技术来维护系统稳定性。他回顾了YouTube的核心技术选型——包括Apache、定制的Wise Guy FastCGI容器、结合Vitess的MySQL、Spitfire模板以及用Lighttpd在两周内搭建的自建CDN——同时敦促工程师优先考虑清晰的数据契约和宏观架构,而非微观优化。 YouTube的核心基础设施严重依赖超过100万行Python代码,经历了从最初的原型到应对每日超过40亿次观看、达9个数量级的观看流量增长。 (9:33) 为摆脱昂贵的商业带宽成本,YouTube利用高密度服务器机架、Lighttpd以及Python 404处理器在两周内构建了自研CDN,上线首日即实现了60 Gbps的传输吞吐量。 (35:06) YouTube通过使用Go语言开发Vitess来扩展其MySQL数据库层,以优化查询、建立连接池并通过定制RPC路由流量,打破了关系型数据库无法扩展的观念。 (29:47) 将早期基于HTTP和pickle的内部RPC层替换为直接套接字RPC,使YouTube的全球CPU使用率降低了约8%,而定制的BSON序列化器性能比现成方案高出10到15倍。 (26:47)

Reading summary

Drawing on YouTube's evolution through nine orders of magnitude in view traffic, early engineer Mike Solomon argues that architectural scalability depends on simplicity, loose guarantees, and explicit data boundaries rather than raw execution efficiency. The Tao of YouTube: Simplicity and Flexibility (13:31) Solomon cautions engineers against over-specifying systems or attempting to guarantee strict behaviors upfront, which artificially introduces complexity and closes off architectural escape hatches. Systems should begin with the simplest possible structure—often a single Python file—and allow complexity to evolve naturally over time. Maintaining flexibility is critical because early operational assumptions frequently fail, a lesson reflected in YouTube's early shift away from its original concept as a video dating site. Partitioning, Dynamic Code, and Approximate Correctness (14:50) YouTube scales its systems through divide-and-conquer strategies, using pools of stateless web servers and sharded relational databases. To avoid catastrophic stampedes caused by distributed systems naturally synchronizing, the platform injects artificial jitter into cache lifetimes, scattering a target 24-hour expiration randomly across an 18-to-30-hour window. Engineers also exploit approximate correctness and deliberate cheating. Because a system's state is functionally whatever is reported to users, YouTube avoids expensive global transactions for non-critical features. Comment updates are rendered instantly for the author while propagating eventually worldwide, and high-velocity view counters batch updates in pseudo-random increments instead of triggering transactions on every individual increment. Boundaries, RPC Firewalls, and Data Contracts Because dynamically typed languages like Python lack rigid enforcement, Solomon emphasizes that system structure depends on programmer discipline and strict interface boundaries. YouTube uses explicit Remote Procedure Call (RPC) boundaries as firewalls between subsystems, enabling components with lifespans as short as one to six months to be refactored, rewritten in C, or replaced without affecting surrounding services. Defining explicit typed data objects is critical for controlling cognitive load. Solomon identifies his greatest architectural error as using a generic dictionary with hundreds of arbitrary attributes across the serving and templating boundary, rather than investing the time to construct a typed data object such as a structured watch-page representation. Practical Python Efficiency and Infrastructure Choices (24:26) Macro-level architectural organization and algorithmic complexity offer far larger performance gains than micro-optimizations. YouTube favors plain, readable code that avoids heavy metaprogramming or complex object-oriented hierarchies, instead relying on module-level functions and classes treated as simple data structs. In contrast, profiling reveals that real runtimes are heavily dominated by data serialization and garbage collection. To eliminate bottlenecks, YouTube avoided standard Python pickle, built a custom direct-socket RPC protocol that saved 8% in global CPU usage over an HTTP/pickle predecessor, and authored a custom BSON engine that outperformed stock implementations by 10 to 15 times. YouTube's core infrastructure balances standard software with tailored components. Every request routes through Apache, Wise Guy serves as a preforked synchronous FastCGI container, and Apache ZooKeeper manages distributed locking. The data layer relies heavily on MySQL, fronted by YouTube's Go-based Vitess proxy to optimize and route queries. When commercial bandwidth proved too expensive, YouTube built an in-house CDN in two weeks using dense server racks, Lighttpd, and a custom Python 404 handler to route cache misses, handling 60 Gbps on its first day. Incremental Verification for Live Production Migrations (37:40) To alter active production architectures without outages, YouTube relies on canary rollouts and targeted testing. Migrating active read paths involves routing small, incremental percentages of live traffic to the new backend to measure real-world performance before making a full cutover. For write paths, which present substantially higher risks of data corruption, engineers depend on extensive workload simulations prior to flipping production traffic. Solomon emphasizes that enduring architectures come from understanding the motivations behind engineering decisions rather than copying specific technical designs, acknowledging that real-world production codebases inevitably end up messier than idealized models.

精炼阅读摘要

YouTube 早期核心工程师 Mike Solomon 与开发者布道师 Shannon Behrens 指出,构建超大规模系统最关键的原则是“保持极简并推迟复杂度”,而非盲目追求微观层面的执行效率;YouTube 依托超百万行 Python 代码、松散约束保证以及清晰的架构边界,支撑了视频流量跨越九个数量级的指数级增长。 平台规模扩张与“极简至上”的演进哲学 (9:33) Shannon Behrens 披露,YouTube 每日视频播放量已突破 40 亿次,每分钟上传时长达 60 小时,全球支持设备超过 3.5 亿台。作为 YouTube 首位员工,Mike Solomon 回顾其工程团队在七年间应对了暴增九个数量级的流量冲击,而支撑整套庞大系统的核心代码库中运行着超过 100 万行 Python 代码。核心服务架构、视频索引、转码、搜索和视频分发等关键子系统,起初几乎全是用 Python 快速构建的原型,并在生产环境中持续稳定运行多年。 分治架构、近似正确性与引入随机抖动 (14:50) 应对超大流量的核心手段在于分治策略,在前端表现为无状态 Web 服务器集群均摊请求,在存储端则采用 MySQL 数据库分片。Solomon 强调“近似正确性”的工程价值:系统的真实状态取决于呈现给用户的状态。例如在评论场景下,系统优先为发布者在本地呈现更新,而全球其余用户只需在 300 至 400 毫秒后达成最终一致性;对播放量等单调自增计数器,系统通过批处理与伪随机更新大幅降低数据库 ACID 事务压力。 面对分布式缓存中的惊群效应(Thundering Herd),YouTube 引入了人工随机“抖动”(Jitter)。若将热门视频的缓存失效期固定设为 24 小时,各节点会在同一时刻集体回源冲击数据库;将失效时间随机分散在 18 至 30 小时之间,能够打破分布式节点自发的锁步同步,增加系统熵值并平滑峰值负载。 明确组件契约与反“魔法”的工程实践 (22:04) 动态语言的长期维护高度依赖工程师自律。Solomon 指出,随着团队规模扩大,清晰的 RPC 边界成为了隔离系统复杂度的关键防火墙。他将 Web 服务层与模板渲染层之间使用通用字典传递数据视为自己职业生涯中最严重的架构失误,这一做法导致上百个属性无序隐式流动;他主张应定义严格的数据对象(如 WatchPage)来规范数据输入与输出。 在代码实现上,Solomon 警示不要滥用元编程等高动态“黑魔法”,直白简单的代码不仅便于维护和检索,执行速度也往往更快。YouTube 早期偏向使用命名空间与类 C 结构体的数据容器,搭配模块级函数执行逻辑。底层组件方面,YouTube 摒弃了基于 HTTP 与 pickle 的远程通信,改用原生套接字 RPC,直接为全站降低了约 8% 的 CPU 负载;Web 层则依托 Apache、C 语言编写的 FastCGI 进程容器 Wise Guy 以及 Spitfire 模板引擎,保持同步阻塞式高效运行。 底层基建定制、自建 CDN 与在线热迁移 (29:47) YouTube 选用 Linux 作为基础系统,借由 strace 与 tcpdump 等底层观测工具排查运行时开销。针对海量数据库访问,团队使用 Go 语言研发了数据库中间件 Vitess,部署在 MySQL 集群前端提供查询重写、连接池复用与 RPC 代理,并结合 Apache ZooKeeper 实现分布式锁与全局配置管理。针对 Python 在数据序列化上的性能瓶颈,团队弃用效率低下的默认库,自主开发了比通用方案快 10 至 15 倍的高性能 BSON 引擎,并将其并入 Vitess 项目开源。 为摆脱第三方商业 CDN 昂贵的带宽费用,YouTube 团队利用高密度机架交换机结合 Lighttpd,仅耗时两周便搭起了自研视频 CDN,通过 Lighttpd 的 404 错误跳转 Python 寻址脚本处理缓存未命中,在投产首日即成功承载 60 Gbps 流量。面对生产环境的大规模重构与数据迁移,团队通过小比例金丝雀读流量切分来验证系统表现,对写操作则实施严格的事前离线仿真,确保了高并发下的在线系统平滑演进。 YouTube 的架构演进证明,动态语言能够凭借敏捷的原型迭代能力支撑超大规模服务。其扩展能力的核心不在于底层语言的微观性能,而在于以分治架构、松散约束与抖动容错应对流量爆发,以严格的数据边界控制认知负担,并在网络传输、数据序列化与视频分发等关键性能瓶颈处实施精准的定制替换。

Detailed notes — zh

## Background 该视频由 Next Day Video 于 2012 年 3 月 11 日发布在 YouTube 平台上。页面简介显示,本场演讲聚焦于 YouTube 的可扩展性架构,由 YouTube 早期核心工程师之一 Mike Solomon 主讲,带观众深入一窥全球最大网站之一的心脏地带与底层技术运作。 ## TL;DR 演讲首先由 YouTube 开发者布道师 Shannon -jj Behrens 开场,分享了平台的庞大规模及初创团队借助其生态获取商业成功的策略;随后 YouTube 一号员工 Mike Solomon 登台,系统复盘了 YouTube 基于 Python 构建超大规模系统的可扩展性哲学。Solomon 强调保持极简设计与最宽松保证的重要性,并详细拆解了分而治之、近似正确性、引入抖动机制(Jitter)避免惊群效应等实战策略。他还剖析了明确 RPC 边界与数据契约的必要性,并结合底层架构(包括原生 Socket 替换、Vitess、MySQL、ZooKeeper)以及两周内用 Lighttpd 与 Python 搭建支撑 60Gbps 自研视频 CDN 的传奇经历,阐述了如何在高速狂飙的超大规模流量中兼顾开发效率与系统稳定性。 ## Atmosphere & style 整场演讲呈现出一种极客式幽默与硬核工程务实主义交融的生动氛围。开场 Behrens 以风趣自嘲的段子带动全场热情,随后登台的 Solomon 则以松弛自信且毫不粉饰的姿态,将复杂的架构演进娓娓道来,坦诚吐槽自己在早期犯过的“严重罪行”与技术踩坑史。观众席在听闻仅用两周上线支撑 60Gbps 的自研 CDN 等惊人战绩时反响热烈,问答环节互动精准切中行业痛点,整体观感既充满早期硅谷车库创业般的草莽传奇色彩,又饱含对大规模分布式系统深刻洞见的清醒反思。 ## Bulletin - [00:01](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1s) YouTube 日播放量已突破 40 亿次且每分钟上传 60 小时视频,全站核心服务仍深度依赖超过 100 万行 Python 代码运行。 - [12:10](https://www.youtube.com/watch?v=G-lGCC4KKok&t=730s) 架构可扩展性的核心哲学是追求极简初始设计与最宽松的实用保证,过度设计和过早强约束会剥夺系统应对业务剧变的灵活性。 - [18:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1094s) 超大规模分布式集群具有天然的自同步破坏倾向,必须在缓存过期等场景主动引入随机抖动(Jitter)以打破惊群效应。 - [35:06](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2106s) YouTube 早期为摆脱昂贵的商业 CDN 账单,仅用两周时间基于 Lighttpd 重写 404 处理挂接 Python 脚本,上线首日即抗住 60 Gbps 视频分发流量。 ## Key takeaways - [00:01](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1s) 初创企业可依托 YouTube 生态通过制作爆款内容、深度社群互动、接入开放 API 以及定制创新应用四种策略实现商业增长。 - [10:19](https://www.youtube.com/watch?v=G-lGCC4KKok&t=619s) 系统最初的原型通常足够简陋却极具生命力,YouTube 许多核心管道起步时都仅是一个单文件 Python 脚本。 - [10:19](https://www.youtube.com/watch?v=G-lGCC4KKok&t=619s) 可扩展性(Scalability)与运行效率(Efficiency)并非正相关,过度追求单机执行效率往往会牺牲横向扩展能力与工程开发效率。 - [14:50](https://www.youtube.com/watch?v=G-lGCC4KKok&t=890s) 利用“近似正确性”与用户感知的局限性,在评论等非关键链路放弃昂贵的全局事务与强一致性,可极大提升系统吞吐。 - [18:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1094s) 分布式系统运行类似天气系统充满不确定性,必须在固定周期任务与缓存过期机制中主动注入抖动以防止集群步调一致自我雪崩。 - [18:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1094s) 系统内部可通过合理“作弊”降低压力,例如对递增计数器采用批处理累加结合随机偏移,避免频繁事务开销。 - [22:04](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1324s) 清晰的数据规约与 RPC 隔离墙能赋予子系统热拔插能力,使团队在代码纪律难以维持时快速重写或替换底层实现。 - [22:04](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1324s) 在各服务层与展现层之间传递无约束的通用字典是严重的设计失误,缺乏结构体契约会导致属性不可控膨胀与维护灾难。 - [24:26](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1466s) 选择优良的高阶算法比底层微观调优更重要,借助标准库如 bisect 降低算法复杂度级别即可大幅压低 Python 计算开销。 - [24:26](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1466s) 序列化是大规模服务中的主要 CPU 消耗源,基准测试严禁用合成整数数据替代生产环境中大体积真实文本进行评估。 - [26:45](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1605s) 朴素、无魔法的“愚蠢代码”往往运行更快,YouTube 抛弃繁重 HTTP 协议封装改用原生 TCP Socket 直连为全局节约了约 8% CPU。 - [26:45](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1605s) YouTube 并非异步非阻塞架构,其采用 Apache 配合 Wise Guys FastCGI Prefork 容器,完全以阻塞模型承载庞大请求。 - [29:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1787s) MySQL 既可用作关系型存储也可用作 Blob 存储,YouTube 研发了 Go 语言编写的 Vitess 作为 MySQL 前端代理处理查询重写与聚合。 - [32:04](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1924s) 代码组织应杜绝无增量信息的废弃注释,优先采用扁平命名空间与类似结构体的数据容器,避免深层 OOP 继承结构。 - [36:20](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2180s) 官方 Protocol Buffers 库在 Python 早期环境下开销过高,YouTube 自研了比公开版本快 10 至 15 倍的定制 BSON 实现。 - [37:41](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2261s) 高并发在线系统热迁移应遵循只读流量小比例切流镜像验证、写入流量充分离线仿真的原则,以规避灾难性故障。 ## Detailed walkthrough ### [00:01](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1s) Shannon -jj Behrens 开场:YouTube 的规模与初创策略 Shannon -jj Behrens 以极具幽默感的风格登台 PyCon。他自称是 YouTube 的开发者布道师(Developer Advocate),同时打趣说自己其实就像展台前的“展会女郎”(Booth babe),只不过现场台下的男程序员实在太多,效果并不怎么理想。他拿观众日常看 YouTube 视频的体验开玩笑说:“你知道每次去 YouTube 想看夏奇拉(Shakira)的精彩 MV 时,总得先看一段广告,因为夏奇拉也得赚钱吃饭;而我就是那段广告。” 在调侃过后,Behrens 迅速切入正题,展示了当时 YouTube 的真实运营体量。数据显示,YouTube 每日视频播放量已突破 40 亿次,每分钟上传的视频时长达到 60 个小时。Behrens 调侃道,曾经每分钟只上传 39 小时的时候,所有数据还能勉强塞进单块硬盘里,但如今不得不全面转入 RAID 阵列系统。此外,全球有超过 3.5 亿台设备支持 YouTube,公司在 2010 年营收实现翻番,已经是一个极为庞大且盈利丰厚的业务平台。针对现场的 Python 初创团队,Behrens 提出了基于 YouTube 平台生态获取商业成功的四种核心策略: - 制作病毒式传播的爆款内容(Viral Content),借势获取流量。 - 打造有深度的高质量内容,通过评论区与粉丝社群深度互动。 - 将自身产品与 YouTube 开放 API 进行集成(Integrate)。 - 运用 YouTube API 构筑全新形态的应用体验(Innovate)。 ### [02:25](https://www.youtube.com/watch?v=G-lGCC4KKok&t=145s) 商业落地实战:病毒视频传播与社群互动营销 Behrens 随后现场播放了一段嘻哈说唱风格的极客广告视频,歌词调侃了博客圈、Twitterverse、扎克伯格(Zuckerberg)、科技八卦媒体 Valleywag 和 TechCrunch,描绘了极客在母亲家地下室敲代码做流量、赚取 Google 分成的创业日常。视频播完后 Behrens 揭晓,这其实是一家 VoIP 电话解决方案供应商拍摄的病毒式营销广告:“有趣的是,那些觉得这视频酷毙了的人——比如我自己——恰恰正是最需要 VoIP 解决方案的目标群体。”借助这种高传播度的幽默短片,初创公司无需支付高额营销费用,便能自然撬动海量精准客户。 接着,Behrens 分享了第二个典型案例:一家滑板销售公司。这支团队最初砸下重金在各大主流社交网络上投流买量,试图触达滑板爱好者,但销售转化极差,公司濒临困境。后来他们彻底改变策略:走出办公室拍摄精彩的滑板动作实况视频上传至 YouTube;当观众在评论区询问“你的滑板是在哪儿买的”时,他们便亲自与用户交流并达成销售。现在,通过 YouTube 评论互动并观看其他爱好者的视频,成了他们唯一的营销渠道。Behrens 强调,传统电视广告是单向灌输,根本无法与受众对话,而 YouTube 的核心优势正在于双向的社群互动。 ### [06:48](https://www.youtube.com/watch?v=G-lGCC4KKok&t=408s) 深度整合与创新:从 YouTube Direct 到定制化应用 除了营销层面,Behrens 展示了在产品与技术层面对接 YouTube 的两条落地路径: 第一种是系统整合(Integrate)。YouTube 推出了名为 YouTube Direct 的开源解决方案,它是基于 Google App Engine 构建的应用模板。各类机构(如新闻媒体网站)可以直接将其嵌入自家系统,方便终端读者或爆料用户反向录制并上传视频给平台,从而建立紧密的 UGC 新闻互动生态。 第二种是体验创新(Innovate)。以 iPad 应用《爵士乐历史》(The History of Jazz)为例,该应用制作精美,放在客厅咖啡桌上格外赏心悦目,用户可以通过它直观学习爵士乐发展历程。该团队不仅调用 YouTube API 拉取流媒体视频,还定制了专门的播放器界面,并同时设计了双重变现路径:应用本身是付费下载,而用户在应用内如果喜欢某首配乐,可以直接通过内嵌的 iTunes 购买链接完成付费。 ```mermaid flowchart TD accTitle: YouTube Developer Ecosystem accDescr: 展现 YouTube 为外部开发者提供的四种商业结合策略与两大底层 API 支持体系 subgraph Strategies["四种商业结合策略"] A["病毒式营销内容"] B["社区深度互动 (如滑板公司)"] C["系统集成 (如 YouTube Direct)"] D["产品创新 (如 History of Jazz)"] end subgraph YouTubePlatform["YouTube API 架构支撑"] E["后端: Data APIs<br/>(REST, Atom/JSON, OAuth 2.0)"] F["前端: Player APIs<br/>(JS/ActionScript, Chromeless)"] end Strategies --> YouTubePlatform ``` ### [07:59](https://www.youtube.com/watch?v=G-lGCC4KKok&t=479s) YouTube 开发者体系与 Mike Solomon 登场 在 API 架构层面,Behrens 介绍了面向开发者的两大接口体系: - **数据 API(Data APIs)**:承担后端功能,基于 REST 架构,支持 Atom 和 JSON 数据交换格式(Behrens 开玩笑称自己曾提议用 CORBA 但被无情拒绝),支持利用 OAuth 2.0 代表用户执行上传视频、检索、评分、评论及管理播放列表等敏感权限。官方提供了 Python SDK 以及其他“不值一提的语言”客户端。 - **播放器 API(Player APIs)**:承担前端呈现,支持通过 JavaScript 或 ActionScript 对播放控件实施精细编程,支持修改播放器行为参数,甚至提供完全无边框的纯净播放器(Chromeless Player)供前端二次定制。 在展示了一小段通过 `YouTubeService` 执行查询并按播放量排序获取视频列表的简洁 Python 代码后,Behrens 完成了开场,郑重请出 YouTube 的第一号员工、奠定核心架构的传奇工程师 Mike Solomon。Behrens 赞誉其为“你可能素未谋面、但实际上最为著名的人,因为正是他以一己之力,让全球每一位用户在点击播放键时能够顺畅看到视频”。 ### [10:19](https://www.youtube.com/watch?v=G-lGCC4KKok&t=619s) Mike Solomon 谈技术底色:Python 架构演进与规模爆炸 Mike Solomon 走上讲台后先幽默地假装要从最后一页幻灯片倒着讲,随后坦言要将过去 7 年的系统演化浓缩进 30 分钟极为困难。他计划从宏观视角探讨 YouTube 在可扩展性方面的架构策略,而这些策略不仅适用于 Python,也能迁移到其他任何语言栈中。 Solomon 回顾了他在 YouTube 早期涵盖的广泛技术领域:从搭建底层服务器基础设施、设计视频索引、实现视频转码、编写全文本搜索,到后来从零构建专有的 CDN 网络、视频分发管道(Video Delivery)以及图片分发系统。所有这些核心系统的最初原型完全是用 Python 构建的,并且这些原型在生产环境中扛了令人吃惊的极长时间。针对外界对脚本语言性能的固有质疑,Solomon 直言: > “At last count there was like over a million lines of python running this thing so lest anybody doubt we actually really do use python in a very big way.”(“上次统计时,系统里依然运行着超过一百万行 Python 代码;所以大家完全不必怀疑,我们确实在超大规模的核心业务中深度依赖 Python。”) 即使到了演讲当下,以代码行数衡量,YouTube 绝大部分核心服务逻辑仍然由 Python 承担。每次用户点击播放视频,背后都经过了大量的 Python 代码逻辑。谈及可扩展性,Solomon 指出技术圈常常将“可扩展性”(Scalability)与“运行效率”(Efficiency)混为一谈,而厘清二者的界限至关重要。在他供职期间,YouTube 的视频播放总量增长了整整 9 个数量级,伴随工程师团队的扩张,系统架构遭遇了常人难以想象的极端挑战。 ### [12:10](https://www.youtube.com/watch?v=G-lGCC4KKok&t=730s) 可扩展性的核心哲学:保持极简与松散保证 可扩展性并非单一维度的工程挑战,它横跨编写代码、执行代码以及后续维护等多个维度。在面对可扩展系统时,Mike Solomon 强调如果只能用一个词来概括其精髓,那就是“简单(simple)”。在构建新系统或寻找解决方案时,工程师首先应当寻找能够解决问题的最简方案。复杂问题确实比比皆是,但“第一次尝试没必要那么复杂;复杂度随着时间推移自然会增加,你在刚开始时完全没必要推波助澜”。YouTube 的许多底层系统最初都只是从一个单一的 Python 文件起步,经过多年演化才最终成长为庞大的技术生态。 在架构设计哲学上,如果将这一套思想总结为“YouTube 之道(the Dao of YouTube)”,那就是追求“最简单的方案”与“实际可行的最宽松保证(loosest guarantees)”。过度设计和过度承诺保证只会让团队陷入死角:一旦在前期做出了过于严格的约束与规格定义,系统就会自动变得复杂,后续迭代将失去回旋空间。在工程或产品评审中,最核心的考量应当是:第一步如何落地、未来如何迭代、数据究竟会被如何使用。系统的演进方向往往完全出乎意料,正如 Mike Solomon 指出的一个趣闻:YouTube 最早其实是一个相亲约会网站(dating site),如果当年团队全盘围绕相亲网站去设计底层架构,今天的 YouTube 绝不可能存在。 ```mermaid flowchart LR accTitle: YouTube架构设计之道 accDescr: 展示从简单设计与宽松保证出发,获得应对演进弹性的架构哲学。 subgraph Mindset["YouTube 架构哲学"] A["极简初始方案<br/>(单 Python 文件起步)"] --> B["最宽松的实用保证<br/>(避免过度约束)"] end subgraph Outcome["工程演进收益"] B --> C["高灵活性与迭代空间"] C --> D["适应业务形态剧变<br/>(如:相亲网站转向视频巨头)"] end ``` - Mike Solomon 总结道:“For me a scalable system is one that's not in your way that you're sort of unaware of.”(对我而言,一个具备可扩展性的系统是一个不会妨碍你、让你几乎察觉不到它存在的系统。) - “Stay flexible.”(保持灵活性)是贯穿 YouTube 系统架构设计审查的第一原则。 --- ### [14:50](https://www.youtube.com/watch?v=G-lGCC4KKok&t=890s) 核心可扩展技术:分而治之与近似正确性 可扩展系统的底层手段虽然基础,却能在多个维度发挥作用,其中最重要的莫过于“分而治之(divide and conquer)”。从最简单的 Web 层水平扩展——将请求分散到大量无状态、对等的独立 Web 服务器上并发处理,到数据库的分片(sharding),其核心都是将工作切分,并理清子模块之间所需的通信机制。在早期架构中,Python 的动态特性展现出了巨大优势,即使初期的 API 设计再糟糕,工程师也能通过存根(stub)、动态修改或装饰器(decorator)等手段快速脱身,以极低的成本绕开问题。 另一个极为实用的技巧是“近似正确性(approximate correctness)”。系统科学的第一原则指出:系统的状态本质上就是它被报告呈现出来的状态。只要用户端无法感知到底层数据存在倾斜或短暂不一致,那么这种不一致在用户视角就是不存在的。例如,当一个用户发表了新评论,远在大洋彼岸的另一位用户在几百毫秒后刷新播放页时哪怕暂时看不到该评论,他也毫不知情且不在意;但发表评论的用户本人则期望立刻看到内容,此时系统只需做一些客户端本地渲染或局部回显的小花招(cheat a little bit)即可满足预期。绝大多数操作(如评论)并非金融交易,完全没有必要为了全局强一致性而付出昂贵且过度的分布式事务代价。 - 针对不同的业务场景,需要通过旋钮微调(knob twiddling)采用不同的数据一致性模型: - **用户评论**:写入后不丢失即可,最终一致性(eventual consistency)完全足够。 - **电影租赁**:涉及真金白银的交易,必须采取最严格的保障措施确保扣费与权限记录绝不丢失。 - “Approximate correctness”的核心在于:利用用户感知的局限性,在非关键路径上放弃全局事务,换取极致的吞吐量与性能。 --- ### [18:14](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1094s) 抖动机制与“合谋作弊”的艺术 在现代超大规模分布式系统中,微观事件的相互作用让集群表现得更像复杂的“天气系统”,排查故障就像预测天气一样充满非确定性。分布式系统内部存在一种自发的“自同步(self-synchronize)”倾向:一台机器上的缓慢磁盘 I/O 会拖慢一批请求,导致其他原本无关机器上的并发请求也逐步排队对齐,进而引发吞吐量骤降。系统中的故障在不断抽走整个集群的熵(随机性),使节点步调一致地走向雪崩。为了打破这种由于高度同步而引发的惊群效应(thundering herds),团队必须主动向系统中重新注入熵,这一手段即为“抖动(jitter)”。 最典型的抖动应用场景是缓存失效(cache expiration)。如果热门视频或排行榜数据的缓存超时时间被硬编码设为固定的 24 小时,所有机器将在同一时刻检测到缓存失效,并瞬间同时向后端发起重算请求,造成可怕的惊群风暴。YouTube 的解法是在期望的 24 小时过期时间基础上加入随机抖动区间(例如随机浮动在 18 到 30 小时之间),让失效时间在时间轴上均匀打散。 ```mermaid flowchart TD accTitle: 缓存失效抖动机制对比 accDescr: 对比固定过期时间导致的惊群风暴与引入Jitter后的平滑负载。 subgraph BadCase["无 Jitter(固定 24 小时过期)"] A1["多台机器同时命中 24h 到期点"] --> B1["全部机器瞬间穿透至后端重算"] B1 --> C1["后端击穿 / 惊群效应(Thundering Herd)"] end subgraph GoodCase["引入 Jitter(18 至 30 小时随机浮动)"] A2["过期时间被随机打散在 18~30h 区间"] --> B2["各节点分批、平滑发起后端回源"] B2 --> C2["系统负载平稳,消除自同步风险"] end ``` 除了抖动之外,Mike Solomon 极力推崇在系统设计中合理“作弊(cheating)”。对于单调递增的计数器(例如视频播放量 view count、个人资料访问量),若每次递增都执行一次完整的数据库事务,系统将不堪重负。实际工程中完全可以积累一段时间后执行一次批量更新,并加上一个随机偏移量,只要数字呈现递增且奇偶交替跳变,用户就会觉得数据鲜活真实。 - Mike Solomon 引用前主管的话指出:“My old boss told me that the fastest function call is the one that never happens and I have to agree.”(我以前的老板告诉我,最快的函数调用是永远不发生的调用,我对此深表赞同。) - 分布式节点具备天然的自同步破坏性,系统设计必须主动添加随机性以避免机器步调一致地自我摧毁。 --- ### [21:07](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1267s) 可扩展组件的定义与数据流管理 在设计可扩展的组件与模块时,工程师往往“一见到它就能认出来(you know it when you see it)”。一个优秀且具备扩展性的组件,其通用 API 必然边界清晰,输入输出具备明确、严谨的定义。随着团队规模和代码库的膨胀,系统架构的重心会从单纯的逻辑实现逐步转移到“数据规范”本身。 明确每一个函数产生的数据对象以及数据流在调用链路中的流转过程,能让新加入的工程师在几乎没有文档的情况下快速掌握代码脉络。开发者只需检视传入和传出的数据结构,就能直观理解函数执行前后的状态变化。清晰的数据规约不仅能够有效管理上下游调用方对于返回结果的预期,也是维持超大规模代码库可读性与可维护性的关键基石。 - 严格的数据规范允许工程师直接审查数据对象即可理解整个应用,减少了对陈旧文档的依赖。 - 尽管 YouTube 在早期也存在规范不够完美的情况,但团队始终将清晰的数据契约视为系统扩展能力的重要指标。 ### [22:04](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1324s) RPC 边界与数据规范:从代码纪律到致命错误 Mike Solomon 讨论了随着团队规模扩大,系统设计必须向明确的 RPC(远程过程调用)边界演进的趋势。在 Python 这种动态且灵活的语言中,如果缺乏预先制定的规范,代码结构完全取决于工程师个人的纪律性;而一旦个人纪律无法支撑,最稳妥的解决方案就是筑起一道硬性的 RPC 隔离墙。Solomon 形象地描述这种契约:“好的,我给你传一个整数,你给我返回一个布尔值,仅此而已,这就是我们之间全部的交流。”通过划分出极其干净的组件边界,系统获得了可拔插性(swappability)。第一版组件的寿命可能极短,也许能撑一个月,也许撑六个月,但划清界限能让团队掌握主动权;一旦情况恶化,工程团队可以迅速将其用 C 语言重写,或者直接淘汰替换。 ```mermaid flowchart LR accTitle: RPC Boundary Isolation accDescr: 业务逻辑通过严格的数据契约跨越RPC墙进行隔离和模块替换。 subgraph Srv["业务调用层"] A["调用端代码"] end subgraph Boundary["RPC 墙契约"] B["严格类型入参: Integer"] C["确定类型返回值: Boolean"] end subgraph Impl["后端实现 (可热拔插)"] D["Python 实现"] E["C/C++ 重写版"] end A --> B B --> D B -.-> E D --> C E -.-> C ``` 随着工程师人数剧增,没有任何单一人能够理解整套代码库的全部细节,必须拆分出诸如视频转码、视频搜索、数据库基础设施等定义清晰的子系统。在这些子系统之间,数据规范(Data Specification)是维系稳定性的生命线。谈及此处,Solomon 坦白了自己在 YouTube 犯下的“最严重罪行”:在服务层(Serving Layer)与模板渲染层(Template Layer)之间,居然直接用了一个通用的 Python 字典(Dictionary)进行传参。Solomon 评价道:“这是一件极其愚蠢的事,你们千万不要这么做。”如果当初多花整整 10 分钟定义一个结构化的对象(明确标出播放页面核心包含视频对象、评论列表和相关推荐视频列表),后续就能避免数不胜数的麻烦;而现状是模板层接收到的字典可能混杂着数百个难以捉摸的属性,排查和重构都极度痛苦。 - “好的,我给你传一个整数,你给我返回一个布尔值,仅此而已,这就是我们之间全部的交流。”(“All right, I will give you an integer and you should give me a Boolean back and that's it, that is the sum total of our conversation.” —— Mike Solomon) - “这真的是一个糟糕透顶的主意,你们绝对不应该这么做。”(“This is a phenomenally bad idea, you should not do this.” —— Mike Solomon) - 服务层与模板层之间无契约的字典传递,导致属性膨胀到几百个,成为难以治理的技术债。 --- ### [24:26](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1466s) 效率与可扩展性的权衡、算法红利与基准测试的陷阱 Solomon 再次重申,运行效率(Efficiency)与可扩展性(Scalability)完全没有正相关性,很多时候甚至必须相互妥协。最极致的效率或许是把所有业务塞进一个单进程、完全用 C 语言编写,但这极难横向扩展,而且会极度浪费开发人员的宝贵时间。因此,架构师应当聚焦于宏观层面的切分:何时该做成 RPC 服务,何时保留在进程内行内执行,何时拆为独立的子包。此外,算法本身的选择往往比微观优化更重要。Python 降低了实现优秀算法的门槛,内置的 `bisect` 模块就是典型代表——面对一个偶尔有序的杂乱列表,只需用 `bisect` 进行二分查找,或者将其序列化写到磁盘后再读出,就能以极低的算力开销完成极快的检索。虽然 Python 执行算法的常数时间比 C 语言慢,但它在算法复杂度级别(Order of magnitude)上压低了计算量,架构方向依然是完全正确的。 在谈到效率调优时,Solomon 将 Python 的性能测量比作“看茶叶渣占卜(Tea-reading)”,极度违反直觉。很多开发者以为凭借经验可以进行直觉推断,但直觉往往是错的,例如垃圾回收(GC)的隐性成本。YouTube 应用的大部分时间实际上都消耗在“序列化(Serialization)”上,而给序列化程序做 Profiling 就像检视下水道:“流出什么完全取决于你塞进去了什么。”如果在性能测试中只塞进一堆纯整数(Synthetic Data),得出的基准数据看似漂亮,但在生产环境中真正流经管道的却是 4KB 大小的 Unicode 文本块,实际表现必然天差地别。 - “最极致的高效可能是把所有东西塞进一个进程并用 C 编写,但这可能根本不具备扩展性,尤其是当你珍惜自己的时间的时候。”(“The most efficient thing would be to cram everything in one process, write it in C, whatever, but that may not be particularly scalable, especially if you value your own time.” —— Mike Solomon) - Python 内置的 `bisect` 等模块允许开发者以极少代码实现高效算法,以低算法复杂度弥补解释型语言的性能劣势。 - 绝不能仅仅使用整型合成数据测试序列化器性能,必须使用包含大块 Unicode 数据等贴近生产负载的环境进行基准评估。 --- ### [26:45](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1605s) “愚蠢”的代码更快:Python 性能哲学与底层库改造 在 Python 中获取效率的秘诀,不在于使用多少高深的库,而在于“明确知道什么事情绝对不能做”。过度使用元编程(Metaprogramming)和高度动态的特性,其开销与 Python 程序的运行成本呈直接正相关。Solomon 强调:“愚蠢的代码往往才是运行最快的(Dumb tends to turn out to be fast)。”越朴素、越少语法魔法的代码,不仅 CPU 开销小,还极其利于开发人员用基本的 Emacs 和 `grep` 进行全工程排查和快速维护。 在基础底层库方面,Solomon 列举并点评了 YouTube 实际使用的组件与调优实战: 1. **HTTP 客户端与底层 Socket 替换**:几乎所有的客户端 HTTP 库都表现不佳,而 `cURL` 算是其中“最不烂的一个”。在 YouTube 最近的一个重大项目中,他们尝试用基于 HTTP 的实现替换某个主干协议,尽管数据序列化采用了 C 语言加速的 `cPickle`,但在网络链路上消耗的时间依然极其惊人。最终团队彻底撕掉 HTTP 封装层,改用 Python 直接操作原生 TCP Socket,这一举措直接为全局节省了约 8% 的 CPU 资源,印证了 HTTP 报文打包解包的昂贵代价。 2. **Web 容器与并发模型**:YouTube 内部使用的是名为 Wise Guys 的 FastCGI 容器,包含部分 C 语言代码、进程管理与预分叉(Prefork)逻辑。Solomon 明确指出:“YouTube 不是异步非阻塞架构,所有东西都是阻塞式的。” 3. **Apache HTTP Server**:YouTube 依然视 Apache 为坚如磐石的核心技术,每一个用户发起的视频观看请求在某种层面上都会穿透 Apache。 4. **Spitfire 模板引擎**:其架构类似于 Cheetah,内部具备抽象语法树(AST),允许编译器对模板代码进行 AST 级转换与深度优化,大幅提升渲染性能。 5. **序列化格式警示**:所有序列化格式在规模化下都非常昂贵,团队必须时刻测量,并且 Solomon 特别警告:“千万不要在生产环境使用 pickle,我们用过,绝对是个坏选择。” - “愚蠢的代码往往才是运行最快的。”(“Dumb tends to turn out to be fast.” —— Mike Solomon) - “YouTube 不是异步的,一切调用都是阻塞式的。”(“YouTube is not asynchronous, everything is blocking.” —— Mike Solomon) - 抛弃繁重的 HTTP 协议封包、转为直接基于原生 Socket 进行通信,使 YouTube 的全局 CPU 消耗降低了约 8%。 --- ### [29:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1787s) 基础设施基石:Linux、MySQL、Vitess 与 ZooKeeper 在底层基础设施层面,Solomon 逐一剖析了支撑 YouTube 庞大流量的核心工具: ```mermaid flowchart TD accTitle: YouTube Backend Core Stack accDescr: 展现从前端Web层到底层存储与配置中心的核心组件拓扑。 Client["客户端请求"] --> Apache["Apache HTTP Server"] Apache --> WG["Wise Guys FastCGI 容器\n(Python 阻塞模型 / Prefork)"] WG --> Spitfire["Spitfire 模板引擎\n(AST 优化)"] WG --> Vitess["Vitess Proxy (Go 编写)\nRPC 接口 / 动态查询重写与优化"] subgraph Storage["数据层"] Vitess --> MySQL["MySQL 集群\n(关系数据库 / Blob Store)"] end subgraph Infra["运维与协调"] Linux["Linux (strace / tcpdump 可观测性)"] ZK["Apache ZooKeeper\n(配置分发 / 分布式锁)"] end Vitess -.-> ZK WG -.-> Linux ``` - **Linux**:作为全站运行的底层系统,Linux 提供了无与伦比的“人孔(Manholes)”与可观测通道。不论上层编写的应用程序多么糟糕或混乱,它所消耗的系统资源始终可以通过 `strace`、`tcpdump` 等底层基础工具探索和定位,这是构建分布式系统不可或缺的能力。 - **MySQL**:YouTube 重度依赖 MySQL,用户每次观看视频都在从 MySQL 大规模读取数据。YouTube 既将其当作传统关系型数据库使用,也将其当作纯粹的 Blob 键值存储使用。Solomon 驳斥了外界对该技术的偏见,直言任何盲目宣称“MySQL 无法扩展”的人,通常根本没有认真思考过如何针对特定场景去组织和调优数据。 - **Vitess**:这是 Solomon 当时深度参与的全新开源项目,使用 Go 语言编写,作为 MySQL 的智能前端代理。它负责在运行时对 SQL 进行动态重写、查询优化和代理聚合。Vitess 对外提供高效的 RPC 接口,在演讲当时已经承载了 YouTube 全站每一个数据库请求的转发服务。 - **Apache ZooKeeper**:Solomon 幽默地调侃,ZooKeeper 是“唯一能让我觉得 Java 还有救的软件”。在 YouTube 内部,ZooKeeper 被当作一个极度高可用的分布式文件系统和锁服务器,广泛用于各种系统的动态配置管理。 - “任何盲目地告诉你 MySQL 无法扩展或者做不到某些事情的人,大概根本没有想清楚到底该如何解决问题。”(“Anybody who sort of blindly tells you that MySQL doesn't scale or doesn't do something probably has not considered exactly how to solve the problem.” —— Mike Solomon) - “ZooKeeper 是那款让我觉得 Java 也许还能被拯救的孤胆软件。”(“ZooKeeper is the lone piece of Java software that makes me think that Java might be redeemable.” —— Mike Solomon) - Vitess 采用 Go 编写,替代了高开销的 HTTP 接口,以定制 RPC 协议支撑 YouTube 每一个数据库查询。 ### [32:04](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1924s) 软件工程哲学与代码组织:追求简单与实用主义 Mike Solomon 转向讨论开发生产力(productivity)与代码设计哲学。他直言这些话题略显抽象,但他更坚信哲学原则而非僵化的教条。当团队要求代码保持“简单”时,很难给出一个精确的死定义,但“当我看到它时我就能识别出来”。如果一位新工程师在第一次代码审查(Code Review)中提交了跨越许多文件、多达数千行的代码,这通常意味着实现方式走入了过度复杂的歧途。团队所倡导的开发模式是:先用最简单、直接的方式做出最小可行 Demo,让它能够运行起来,随后再逐步迭代改进。 谈及代码编写规范,Solomon 分享了自己最不能忍受的糟糕习惯——无意义的冗余文档注释。例如,给一个名为 `video_id` 的函数参数写上一行形如 `@param video_id: this is the video ID` 的注释。他吐槽自己的屏幕很小,每一行显示空间都极其宝贵,这种毫无增量信息的废话注释不仅占据宝贵的屏幕空间,而且任何人看名字都能猜出它是视频 ID。在代码架构方面,YouTube 的 Python 代码库很少采用深层次的面向对象编程(OOP),而是大量使用命名空间(Namespaces)以及类似于 C 语言结构体(struct)的方式来组织数据。早期在 Python 环境下,模块级函数比类方法调用要快得多,尽管 Python 2.6 及更新版本引入了更好的缓存机制,但这种推崇平铺、简洁、结构化的组织方式依然贯穿始终。 ```mermaid flowchart TD accTitle: YouTube 开发与代码设计哲学 accDescr: 展示从简单原型到迭代优化的流程,以及代码组织偏好 subgraph DevFlow["开发与迭代流"] A["简单可行的首版 Demo"] --> B["快速验证与运行"] B --> C["持续迭代与重构"] end subgraph CodeStyle["代码组织规范"] D["平铺命名空间 & 类似 Struct 的数据容器"] E["杜绝废话注释 (拒绝无意义的 @param)"] F["避免复杂的 OOP 继承层级"] end DevFlow -.->|"指导原则"| CodeStyle ``` - Mike Solomon 在谈到设计标准时直言:“Frankly I believe more in philosophy than Doctrine like we try to say like simple all right make it simple what does that mean I don't know but I'll know it when I see it like if you come to me in your first code review is you know thousands of lines and many many files probably there was an easier way for you to do it and that's how I want you to start and you know your first demo should be simple get it working then iterate.” - 针对低效注释,他明确表态:“My personal pet peeve is documentation where people put like a function R called video ID and then a comment saying our colon video ID space this is the video ID like great now I lost like two lines of header... please don't write this again.” - 他还分享了自己向前辈学习的心态:与其机械地复制别人做过的事情,不如去理解“究竟是什么驱动这个人做出这种技术决策”。演讲幻灯片中还幽默地展示了“代码盆栽(Code Bonsai)”的概念——理想中的代码树修剪得典雅优美,而现实中的代码库则充满妥协与繁复。 --- ### [35:06](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2106s) 问答环节:两周搭建支撑 60Gbps 的自研视频 CDN 演讲进入现场提问环节。第一位观众走到麦克风前,询问 YouTube 在自建 CDN 或视频分发方面采用了哪些具体技术方案。 Solomon 解释说,YouTube 创立之初是将视频和图片的 CDN 分发外包给第三方厂商的。然而,随着流量爆炸式增长,商业 CDN 的账单变得“高昂得令人发疯(psychotically expensive)”,当规模跨过临界点后,自建 CDN 便成了唯一的经济选择。令人惊讶的是,只要拥有一名优秀的硬件工程师,用极其简单的开源工具就能搭建出一套性能卓越的视频 CDN:他们装配了一个巨大的机架,塞满服务器,连接上优质的网络交换机;软件层面上直接运行 Lighttpd(Lighty),然后通过覆盖其 404 错误处理程序(404 Handler),挂接一段轻量级的 Python 脚本。一旦本地缓存未命中触发 404,该 Python 脚本就会自动找到正确的源站视频并拉取分发。这套自研架构仅仅用了两周时间就开发完成并上线,在投产第一天就承载了高达 60 Gbps 的峰值流量。 - Mike Solomon 谈及商业 CDN 的开销与自研动机:“YouTube originally contracted out some CDN work for video and for image serving this is of course psychotically expensive and after some point it makes sense to do it yourself.” - 他用极简的语气总结了初代视频 CDN 的诞生与威力:“So basically build a very large rack stick a bunch of machines in it put a good switch in then take Lighty and override the 404 Handler to be a piece of python that knows where to find the video that you didn't find that took two weeks and on its first day served 60 gigabits.” --- ### [36:20](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2180s) 问答环节:Protocol Buffers 序列化瓶颈与高性能 BSON 第二位提问者来自一家拥有约 8000 万用户的团队,对演讲中的架构痛点感同身受。他提到在 Python 环境下进行跨进程/跨服务数据传递时,Google 的 Protocol Buffers 官方库性能极差(Python 2.3/2.4 下纯 Python 实现太慢,而实验性 C++ 绑定又不够稳定),导致大量 CPU 时间被浪费在序列化上;为此他们不得不自研了一套名为“Palm”的 C 语言薄封装库,并已在 GitHub 开源。 Solomon 赞同了这个关于“Protocol Buffers 究竟快不快”的质疑,直截了当地指出其在 Python 下确实并不算快,尽管后续版本在持续改进。这也再次印证了性能监控与度量的重要性。作为应对序列化瓶颈的方案,YouTube 内部重写并使用了一套专用的 BSON(Binary JSON)实现,其序列化与反序列化速度比公开可下载的标准版本快上 10 到 15 倍。Solomon 透露,YouTube 计划将这一高性能 BSON 实现作为开源项目 Vitess 的一部分回馈给社区。提问者也附和表示,他们之前也曾因为 Protobuf 太慢而转向 MongoDB 的 BSON 库作为过渡。 - 针对 Protocol Buffers 的实际性能,Mike Solomon 回应:“The question was Loosely we're trying to use protocol buffers are protocol buffers actually fast the answer is kind of no but they're they're going to get better.” - 关于 YouTube 内部的序列化解决方案,Solomon 说明:“We have a bson implementation that we wrote that is 10 15 times faster than the one you can download we are open sourcing it as part of the Vitess project.” --- ### [37:41](https://www.youtube.com/watch?v=G-lGCC4KKok&t=2261s) 问答环节:高速行驶中换轮子——高流量系统的数据热迁移 最后一位提问者抛出了一个许多后端工程师面临的经典困境:“对于那些不幸需要在承载巨大流量的在线系统上实现全新功能的工程师,应该怎样做?是应该镜像生产环境流量,还是去编写高质量的现有流量模拟程序?” Solomon 将这一挑战形象地比喻为“在汽车全速飞驰的同时更换车轮(how do you change the wheels while the car is running)”。他回顾了自己在 YouTube 负责过的大量大规模数据迁移项目。实际操作中,面对复杂的在线系统,通常的策略是循序渐进:先将小比例(百分比级别)的只读(Read)流量分流镜像到新系统上进行验证;而对于写入(Write)流量,由于涉及状态持久化和一致性,往往需要做充分的离线模拟仿真测试,在确信万无一失后才逐步切流。在这个过程中,工程师必须在业务底层明确不同数据访问模式的取舍,并做好细致的监控与应急预案,同时在心里“祈祷好运(cross your fingers)”。凭借这种谨慎的分流验证与推演,YouTube 在多次核心数据重构与热迁移中均未发生重大灾难性事故。在简短答复并致谢观众后,整场演讲在热烈的掌声中圆满落幕。 - Mike Solomon 提炼该问题的核心矛盾:“Oh so the question is how do you change the wheels while the car is running.” - 针对读写迁移的实操原则,他解释道:“Right now when we do a big data migration we frequently route some percentage of read traffic and then the rights pretty much have to be real sure that it's going to go you run a simulation and cross your fingers and and so far we haven't had any major disasters but that's pretty much the only recipe there is.” ## Notable quotes > [29:47](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1787s) Anybody who sort of blindly tells you that MySQL doesn't scale or doesn't do something probably has not considered exactly how to solve the problem. — Mike Solomon > [24:26](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1466s) The most efficient thing would be to cram everything in one process, write it in C, whatever, but that may not be particularly scalable, especially if you value your own time. — Mike Solomon > [12:10](https://www.youtube.com/watch?v=G-lGCC4KKok&t=730s) For me a scalable system is one that's not in your way that you're sort of unaware of. — Mike Solomon > [26:45](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1605s) 千万不要在生产环境使用 pickle,我们用过,绝对是个坏选择。 — Mike Solomon > [26:45](https://www.youtube.com/watch?v=G-lGCC4KKok&t=1605s) 愚蠢的代码往往才是运行最快的。 — Mike Solomon ## Mentioned YouTube, Mike Solomon, Shannon -jj Behrens, Python, MySQL, Vitess, Apache ZooKeeper, Apache HTTP Server, Lighttpd, Go, Linux, Protocol Buffers, BSON, FastCGI, Spitfire, Google App Engine ## Video description Shannon -jj Behrens, Mike Solomon This talk covers scalability at YouTube. It's given by one of the original engineers at YouTube, Mike Solomon. It's a rare glimpse into the heart of YouTube which is one of the largest websites in the world, and on [Source](https://www.youtube.com/watch?v=G-lGCC4KKok)

Source quotes

[29:47] Mike Solomon: Anybody who sort of blindly tells you that MySQL doesn't scale or doesn't do something probably has not considered exactly how to solve the problem. [24:26] Mike Solomon: The most efficient thing would be to cram everything in one process, write it in C, whatever, but that may not be particularly scalable, especially if you value your own time. [12:10] Mike Solomon: For me a scalable system is one that's not in your way that you're sort of unaware of. [26:45] Mike Solomon: 千万不要在生产环境使用 pickle,我们用过,绝对是个坏选择。 [26:45] Mike Solomon: 愚蠢的代码往往才是运行最快的。

Source quotes

[33:14] Mike Solomon: Whenever I talk to some really smart dude, I always feel like what motivated this guy to make these decisions—that’s more what helps me make good decisions than trying to actually repeat what he did. [12:10] Mike Solomon: if I could give you one word about scalable systems I think the word would be simple

Original transcript

[0:01] hey guys welcome to Pyon my name is JJ [0:03] baren I am a developer advocate for [0:06] YouTube also known as a booth babe um [0:09] it's not working there's too many guys [0:10] out there I think that's a problem uh [0:14] you know how you go to YouTube and you [0:16] want to watch like an awesome Shakira [0:17] video and then sometimes like you got to [0:19] see an ad because Shakira needs to get [0:20] paid um I'm I'm that commercial but [0:24] actually I'm going to do something talk [0:26] about something useful I'm here to talk [0:27] about using YouTube for python based [0:29] startups [0:30] um if you're interested in using the [0:32] YouTube API uh there we are on Twitter [0:35] Youtube Dev and then you could also [0:37] email me at um or check out my blog at [0:39] gx. [0:41] blogspot.com so let me give you some [0:43] background information on YouTube [0:45] YouTube gets more than 4 billion views a [0:48] day those are video views UH 60 hours [0:51] worth of video is uploaded to YouTube [0:53] every single minute used to be that we [0:56] would only get like 39 hours a minute [0:57] and we could fit in on a single hard [0:59] drive but these days [1:00] we had to go to [1:01] raid um and then more than 350 million [1:05] devices around the world are YouTube [1:07] enabled and back in 2010 our Revenue [1:11] more than doubled so it's actually a [1:13] very profitable business but you know [1:16] why am I talking about this when I'm [1:17] supposed to be talking about you know [1:20] python for you know YouTube for python [1:22] startup you know how do you guys get a [1:24] piece of the action so I'm going to give [1:27] you four strategies to get a piece of [1:29] the action you could build meaningful [1:31] you could build content that goes viral [1:33] and uh ride the wave you could build [1:36] meaningful content and interact with the [1:38] community uh YouTube has a great [1:40] Community you can integrate your product [1:42] with YouTube apis I'm going to show a [1:44] little bit of that and then I'm going to [1:46] show how you could build new types of [1:48] applications using YouTube apis and then [1:50] all of these approaches have been [1:53] successful for various companies so let [1:56] me start with this [1:59] [Music] [2:04] backup [2:08] [Music] [2:17] [Music] [2:25] plan yeah in the blere now I'm in the [2:29] Twitter verse F get so immersed but I'm [2:31] a ner forever I'm the new Zuckerberg and [2:34] since my website I've been cooking dough [2:36] like a chef serving Killer B used to be [2:38] the basement back at my mom's place [2:41] building web traffic so that we could [2:42] sell an ass Bas make way forth one okay [2:46] so since I have no useful content I'm [2:48] going to start over with [2:50] [Music] [2:57] that yeah now I'm in the Blogger sphere [3:00] now I'm in the Twitter verse fans get so [3:03] immersed but I'm a nerve forever I'm the [3:05] new Zuckerberg and since my website I've [3:08] been cooking dough like a chef serving [3:09] kilabytes used to be the basement back [3:12] at my mom's place building web traffic [3:14] so that we could sell an ad space make [3:16] way for the on man businesses baow [3:19] finish with white color criminals you [3:22] Sega Genesis entrepreneur time making [3:24] big plans to dominate the online yeah [3:27] I'm on YouTube this is one sharing [3:30] Google Revenue with songs on my webcam [3:32] science is the new art databas is dayto [3:35] day be spreading cheat smarts hustle [3:37] make the data pay I could be in [3:39] valleywag plus geology tell from my [3:41] avatar that I'm most [3:44] [Music] [3:46] definitely social networks [3:49] [Music] [3:50] treat there's nothing you can do [3:57] now this seem mommy [4:01] is the is down [4:10] down catch me up in Tech crunch right on [4:13] the hom page H is Moto in [4:18] a okay so if you want VC money don't [4:21] talk to me you got to go talk to Paul [4:23] Graham uh so you might be wondering why [4:25] the heck did I just waste like minute [4:26] and a half of showing you a video that's [4:29] actually an advertisement for a viip [4:31] solution and at the end it shows you the [4:34] advertisement and the funny thing is the [4:36] type of people who think that video is [4:37] freaking awesome like me um are the type [4:40] of people who are more likely to need a [4:42] viip solution and so you know you make [4:45] this video it goes viral and then [4:46] suddenly you don't have to pay for [4:48] marketing cuz it's [4:49] free but um there's other approaches so [4:53] let me show you the next one [4:57] [Music] [5:12] w [5:50] okay so what's that about so these guys [5:52] sell skateboards and they were spending [5:54] a lot of money on various uh social [5:56] networking sites trying to you know tune [5:59] into this skateboarders and they weren't [6:01] selling a lot of skateboards which is [6:02] kind of a problem if that's your [6:03] business so what they figured out is [6:06] let's go out let's shoot some awesome [6:08] videos let's post them on YouTube and [6:10] then when people are like hey where'd [6:12] you get your board let's talk to them [6:14] and that is now their entire strategy [6:17] they just talk to people online with the [6:20] YouTube comments they you know they [6:23] watch videos from other people that's [6:25] that's their whole marketing strategy [6:27] and I talked to these guys and they're [6:28] like yeah we're not doing anything else [6:30] this worked better than you know [6:31] spending money on anything else this is [6:33] all we're doing from now on and so if [6:36] you YouTube is a great way to engage [6:38] with your community with a TV you can't [6:40] really talk back to the customers but [6:42] with YouTube you [6:44] [Music] [6:45] can [6:48] so so the next approach to uh using [6:51] YouTube for your business is to [6:53] integrate we have a open source solution [6:55] called YouTube direct and this is an app [6:57] engine based application that you could [6:59] um embed into your into your website and [7:03] allow users to upload videos to your [7:05] application and a bunch of news agencies [7:08] use this um and so your users can talk [7:11] to you by feeding videos back to you and [7:13] this builds [7:14] Community uh the next approach to using [7:17] YouTube is to innovate uh this is the [7:20] history of jazz it's an iPad application [7:24] and it basically it teaches you the [7:26] history of jazz so it's this beautiful [7:27] application you leave it on your coffee [7:29] table and people come over and they're [7:30] like oh what's this this is pretty cool [7:32] and it teaches you about the history of [7:34] jazz that shows you know videos and [7:37] music and the beautiful thing about this [7:39] is a it's a paid app so these guys are [7:42] making money like right out the get-go [7:43] and then B if you like the songs it has [7:45] iTunes integration so you could go bu [7:48] the music so they have multiple [7:49] monetization strategies and so they're [7:52] doing uh integration with YouTube apis [7:54] in terms of pulling down videos and also [7:56] they have a customized player experience [7:59] okay so building YouTube enabled [8:01] applications we have two types of apis [8:04] uh Google data apis these are the [8:05] backend and then player apis those are [8:07] the front end uh the data apis they're [8:10] rust based um using Adam and Jason I [8:13] tried to talk them into using something [8:15] um like corba but they said no I don't [8:18] know why uh we have client language we [8:20] have client libraries available for [8:22] Python and other less important [8:24] languages that don't bear mentioning uh [8:26] you could upload search rate comment [8:29] manage playlist Etc and you could do [8:30] things on the user's behalf using ooth 2 [8:34] so you know you could play with his [8:36] account upload videos to his account you [8:38] know play with his uh playlist and so [8:39] forth using our player apis uh you could [8:42] control the player and create a [8:44] customized player experience using [8:46] JavaScript or action script and you [8:48] could do a bunch of simple things using [8:50] player parameters and we even have a [8:51] chromeless version of the player and [8:53] because this is a python talk and I'm a [8:55] python guy I figured I should show some [8:57] python code so here is an example [8:59] example of accessing a feed in Python so [9:03] we create a YouTube service object we [9:05] create a query we're going to search for [9:06] python we order it by view count here's [9:09] the feed uh when we do the query and [9:12] then for each of the entries in the feed [9:14] uh we could print the title and get the [9:16] Euro and do whatever else and that's [9:19] about it it's really that easy so um if [9:23] you want to do this just Google for [9:25] Youtube apis uh where YouTube Dev on [9:27] Twitter there's my blog again [9:30] and uh make sure you read the terms of [9:31] service and the monetization guide now [9:33] I'm done I'm done doing my booth Bay [9:36] duties um I'm here to introduce uh Mike [9:39] Solomon Mike Solomon is the most famous [9:41] person that you might not know because [9:43] he was the first employee at YouTube and [9:46] is responsible for singlehandedly [9:49] delivering every single video when a [9:51] person clicks play so Mike saing [10:04] all right let's start from the back no [10:06] no I'm just [10:15] kidding all right hello as JJ said my [10:19] name is Mike Solomon um I work at [10:21] YouTube and it's pretty tough to [10:24] condense s years down into 30 minutes so [10:26] I'm going to try and just talk at a [10:28] pretty high level about [10:30] uh some of the techniques we use [10:32] generally [10:33] for they generally apply to python but [10:36] they apply to all their programming [10:37] languages it's just about sort of [10:39] scalability strategies and and you know [10:41] how do you solve various problems that [10:44] that end up growing over [10:46] time [10:48] so um in my time at YouTube I've worked [10:51] on a very a lot of different systems so [10:54] I started out U building the seral [10:56] infrastructure doing video indexing V [10:59] trans transcode full teex search built a [11:02] CDN um built video delivery built image [11:06] serving and all these things had had the [11:09] prototypes were done in Python and the [11:11] prototypes lived for a surprisingly long [11:13] time um and today most of our [11:16] infrastructure by lines of code is still [11:18] actually in Python and every time you [11:20] actually watch a video you're you're [11:21] still actually you're going through a [11:23] bunch of python stuff and um at last [11:26] count there was like over a million [11:27] lines of python running running this [11:29] thing so uh lest anybody doubt we [11:32] actually really do use python in a very [11:34] very big [11:35] way um so the talk nomally is about [11:39] scalability but I find that people often [11:42] confuse or conflate scalability and [11:44] efficiency so I'm going to try and pick [11:45] them apart and talk a little bit about [11:47] both because they're both important [11:49] especially when things get very large [11:50] and I think that's mostly what people [11:51] are probably interested in is what what [11:53] happens when things get sort of Beyond [11:55] Your Wildest expectation um during [11:58] during the time I've worked there the [12:00] you know in terms of of what has quote [12:02] scaled up um the amount of videos viewed [12:06] has gone up nine orders of magnitude and [12:08] the number of developers working on it [12:10] has gone up two so um you know [12:13] scalability is sort of a problem that [12:15] grow that has many axes and it's you [12:17] know how do you write code how do you [12:19] you know execute code and how do you [12:21] maintain it that kind of stuff so [12:23] hopefully [12:24] uh hopefully this will give you some [12:26] ideas and how they might apply to your [12:28] own problems [12:31] so very generally about scalable systems [12:34] I mean the if I could if I could give [12:35] you one word about scalable systems I [12:37] think the word would be simple and every [12:39] time I'm trying to build something new [12:40] or look at at a way to solve a problem [12:43] I'm looking for the most simple thing [12:44] that will actually you know address the [12:46] problem space and um you know thing [12:51] there are lots of complicated problems [12:53] but the first crack doesn't have to be [12:55] that complicated the complexity will [12:57] come over time naturally you can start [12:59] you don't have to help it out at the [13:00] beginning so a lot of YouTube systems [13:03] you know start out from you know one [13:06] python file uh and it becomes some large [13:09] ecosystem after many many years and that [13:11] whole process is is really what you know [13:13] scalability is about I mean for me a [13:16] scalable system is one that's not in [13:18] your way that you're sort of unaware of [13:19] you know it's not you know it's not [13:22] buzzwords or anything like that it's [13:23] just about a general problem solving [13:26] ethos [13:31] so thinking about how to express this in [13:34] a in a very Zen way oh sorry let me move [13:37] these [13:39] oh there we go um so if I had to pick [13:43] the the Dow of YouTube this this would [13:45] kind of be it right like the simplest [13:47] solution possible the loosest guarantees [13:49] that that are actually practical and the [13:51] reason that you want all these things is [13:52] because you need flexibility to solve [13:54] problems and the minute you overs [13:56] specify something you paint yourself [13:58] into a corner you're not going to be [13:59] able to to make those guarantees and you [14:02] know the your problem becomes [14:04] automatically complex when you're trying [14:06] to guarantee everything and you you [14:08] leave yourself no way out so this is you [14:11] know whenever there's a product design [14:12] review or you know more likely an [14:14] engineering design review these are the [14:16] types of things that that we're always [14:17] looking to to encourage you know what's [14:20] the first crack how are you going to [14:21] iterate how you know what you know what [14:24] do we know about the way that this data [14:25] is going to get used these things change [14:27] over time so how YouTube was originally [14:30] designed had no bearing on what it [14:32] actually became [14:34] so does anybody know that YouTube was a [14:36] dating [14:38] site yeah there you go so do not like if [14:42] we had designed for that I think we [14:44] would be having a substantially [14:45] different conversation so stay [14:49] flexible [14:50] um so scalable techniques um you know [14:55] these are these are probably not new [14:56] things but it's amazing how just a few [14:59] core ideas can apply in a lot of [15:00] Dimensions so divide and conquer I mean [15:04] this is like the the scalability [15:05] technique right here everything is about [15:08] partitioning out work deciding how to [15:10] execute it Etc and this applies to so [15:12] many things from you know in the in the [15:15] simplest expression you think about your [15:16] web tier I'm going to have a bunch of [15:18] web servers and they're all going to [15:19] operate independently that's divide and [15:21] conquer I'm going to spray them out it [15:23] doesn't really matter they're all more [15:24] or less equivalent I'll process them you [15:26] know no problem [15:30] um this is also you know the the Crux of [15:33] database charting and that kind of stuff [15:34] it's all about how do you partition the [15:36] problem how do you figure out what kind [15:38] of communication you need between the [15:40] parts uh that you that you've [15:42] subdivided those are things that you [15:44] want to think about early on and really [15:45] influence how the system is able to grow [15:48] and again simple and loose connections [15:49] here are are really valuable um they let [15:52] you you know this is essentially another [15:54] great feature of python if you because [15:57] everything's Dynamic if you even no [15:59] matter how bad your API is the first [16:01] crack you can pretty much stub or modify [16:04] or decorate your way out of a lot of [16:07] problems so that definitely have used a [16:09] lot of dirty tricks to get something to [16:11] work um you know approximate correctness [16:15] is another one of my favorite techniques [16:18] um this is sort of a you know one of the [16:20] first rules of of systematics is the [16:24] state of the system is that what it [16:25] which is reported to be so if you can't [16:28] tell that that your system is [16:29] fundamentally skewing and and [16:31] inconsistent as from the user [16:33] perspective then it's not so um I mean [16:38] this you know a real world manifestation [16:39] of this is say you you write a new [16:43] comment and somebody on the other side [16:45] of the world you know loads the watch [16:48] page and even though the comment might [16:49] have been made you know a microsc before [16:52] he might not get it for you know [16:54] whatever 300 400 milliseconds you know [16:57] but he doesn't know that so he doesn't [16:58] care now you the you the owner of that [17:01] who wrote the comment expect to see it [17:03] so we should you know maybe do a few [17:04] little tricks to make sure that you see [17:05] the comment and that's you know you [17:08] cheat a little bit right you cheat to so [17:10] that your your system doesn't have to [17:11] have globally like worldwide consistent [17:13] transactions because that would be super [17:15] expensive and you know kind of Overkill [17:17] I mean it's not like every comment is [17:19] actually a financial transaction so kind [17:22] of knowing knowing when to cheat is also [17:24] I think that's on the on the slide [17:26] that's another important important [17:27] aspect of uh [17:30] scalability um in terms of relational [17:33] database systems and storage systems in [17:36] general you I put up expert knob [17:38] twiddling it's like well what do you [17:39] know about what about your consistency [17:41] model you know the comments is a good [17:43] example like okay we want to make sure [17:44] that once they're written they don't go [17:46] anywhere but is eventually consistent [17:49] good enough or is you know is it [17:51] something else like have you rented a [17:52] movie oh well renting a movie sounds [17:54] like you gave us money and we should do [17:56] the best we can to make sure that we [17:57] never lose that so there different [17:59] consistency models based on different [18:00] sub subp parts of the application as a [18:02] whole [18:05] um you know this is this is the Hallmark [18:08] of sort of good system design every [18:09] system is tailored eventually to what to [18:12] its specific [18:14] requirements um Jitter uh this is like a [18:18] hot word in in our group all the time [18:21] you know if your system doesn't Jitter [18:23] you get thundering herds you know I mean [18:27] these days like distributed application [18:28] are really weather systems and a lot of [18:30] debugging them is sort of it's about as [18:33] deterministic as predicting the weather [18:35] and Jitter sort of introduces more [18:37] Randomness because surprisingly things [18:39] have a tendency to stack up so a good [18:41] example for Jitter is um cash [18:43] expirations so if you have a very [18:45] popular video we want to cach things as [18:47] best we can and let's say we set the [18:50] cash time out for I don't know like an [18:52] hour or something or maybe 10 minutes or [18:55] or certain other popular content like [18:57] the most popular videos yesterday we [18:58] might cash for I don't know 24 hours or [19:01] something if everything expires at one [19:04] given time then every every machine or [19:06] will observe that expiration at exactly [19:08] the same time and go back and try and [19:10] compute it this is of course awful and [19:13] this is where you you're basically [19:14] making your own thundering herds by [19:16] jittering you say okay [19:18] well my my desired expiration time is [19:21] about 24 hours I'm going to add some [19:23] variance in there and randomly I'll [19:24] Jitter between say 18 and 30 hours and [19:27] that prevents things from from stacking [19:29] up um we use this all over the place [19:32] because it turns out that systems have a [19:33] tendency to kind of syn self synchronize [19:35] and line up and try to make them destroy [19:38] themselves um so I mean it's actually [19:42] it's fascinating to kind of watch I mean [19:44] you get a slow dis system on one machine [19:46] and everybody is waiting on a request so [19:48] all of a sudden all these other requests [19:50] on completely different machines are now [19:52] synchronized and this happens you know [19:54] when you have many many machines you [19:56] have many types of these events and [19:58] everyone is is actually removing entropy [19:59] from the system so you have to put some [20:01] back in um cheating we covered I'm a big [20:06] fan of cheating actually cheating I [20:07] should cover a little more um because [20:10] it's it's so awesome I mean my old boss [20:12] told me that the fastest function call [20:14] is the one that never happens and I have [20:18] to I have to agree so one of the things [20:21] that we did very early on was we would [20:23] come up with this is sort of in the [20:25] approximate correctness vein is when you [20:29] have monotonically increasing counters [20:31] like you know say view count or how many [20:33] times someone seen my [20:35] profile you could do a full transaction [20:37] every time you wanted to update that or [20:39] you could do a transaction once in a [20:41] while and update by a random amount and [20:43] have and as long as it you know changes [20:45] from odd to even people would probably [20:47] believe that it's real [20:50] um so I mean you you do want the number [20:53] you definitely want to get that where [20:55] the where the sign the the uh odd even [20:58] reverses [20:59] so um know how to fake data too it's a [21:02] good important about think about [21:07] cheating okay uh scalable [21:10] components what can I tell you about [21:13] these you know it when you see it right [21:15] the you can look at the general API and [21:18] have a good um a good feel for how it's [21:21] going to shake out are the inputs well [21:22] defined do I know what I'm getting out a [21:24] lot of this ends up um a lot of this [21:27] ends up being about data and as you know [21:30] the longer I work at YouTube the more [21:31] people we work with the more I think how [21:33] critical data really is like having a a [21:36] very tight specification of what what [21:38] data is coming out of every function or [21:40] or how it flows actually helps you [21:43] understand the application without [21:44] without documentation sort of you can [21:46] pop in there and just grab this data [21:47] object and look at it and say oh okay [21:49] this is what I need or this is what I [21:51] you know this is what's happening you [21:53] know before and after these this [21:55] functions [21:56] applied uh it also lets you sort of [21:59] manage expectations about what's coming [22:00] back and what's not we are actually not [22:02] particularly good at this but we are [22:04] striving to become much better at this [22:06] so we are all learning together [22:09] [Music] [22:10] um things have a tendency to move [22:13] towards rpcs especially in Python I mean [22:16] things are so fast and loose it it ends [22:17] up being you know the structure of your [22:20] code is entirely based on the discipline [22:21] of your programmers so establishing good [22:24] conventions um ahead of time definitely [22:27] helps and when that all else fails you [22:29] stick that RPC wall and you're like all [22:31] right I am I will give you an integer [22:33] and you should give me a Boolean back [22:34] and that's it you know that that is that [22:37] is a sum total of our [22:38] conversation and when you have these [22:40] components you know you want to be able [22:42] to swap them in and out right [22:44] it's your component will not be perfect [22:46] it it may even have a a vanishingly [22:48] small lifetime your first version might [22:50] last a month it might last six you know [22:53] who knows by drawing these lines you [22:55] help yourself you make some of your own [22:57] luck when go south you'll be able to [22:59] swap it out and do something different [23:01] and sometimes that means rewriting [23:02] something in Python and c and sometimes [23:04] it means you [23:05] know getting rid of it entirely or or [23:08] just tweaking a few things you don't [23:10] know you don't know until you you're [23:11] able to uh to [23:14] observe um this is what I was hinting [23:16] about data I mean when you have so many [23:20] people it becomes hard you can't no one [23:22] can know the entire sum total of the [23:24] code base so you have to think about [23:27] components I'm like oh this is video [23:28] trans code video trans code is [23:29] definitely distinct from uh video search [23:33] and the database infrastructure so I [23:35] want you know well-defined subc [23:37] components I mean this is all just like [23:39] basically good software design but a lot [23:41] of these things do end up having to [23:43] communicate with each other and in that [23:46] in that respect I find you know having a [23:47] good data specification is really [23:49] helpful and the like the greatest sin I [23:51] think I ever committed was the interface [23:54] between the the Ser layer and the [23:55] template layer is a dictionary this is [23:58] this is a phenomenally bad idea you [24:00] should not do this um it would have [24:02] taken like all of 10 minutes to actually [24:05] add a meaningful object that says oh [24:06] this is the watch page and the watch [24:07] page substantially has a video some [24:09] comments and some related videos that [24:12] would have solved so many so many [24:14] problems because right now it's a [24:16] dictionary that may have any of like few [24:18] hundred attributes and it's and you know [24:20] things are getting better but you know I [24:23] don't want you to think that we always [24:24] make the right [24:26] choice uh so about efficiency right uh [24:29] as I said it's it's completely [24:30] uncorrelated with scalability uh in fact [24:33] you have to trade one for the other [24:35] right because the most efficient thing [24:37] would be to cram everything in one [24:38] process rate it and see whatever but [24:40] that may not be particularly scalable [24:42] especially if you value your own time [24:43] right um the big thing is is focusing on [24:47] the macro level your components how they [24:49] break out um does it make sense to make [24:51] do this as an RPC or should I just do it [24:53] in line should I break it into a sub [24:55] package and just say okay well someday [24:57] this may be different [24:59] um focusing on the algorithms really [25:01] does make a big difference and you know [25:02] one of the powerful things about python [25:05] is the amount of effort to implement an [25:06] actually good algorithm is is pretty low [25:10] um you have you know all these built-in [25:13] data types but there are really there [25:14] are some other fantastic features like [25:16] the BCT module I mean this thing [25:18] single-handedly you can take a a ratty [25:21] list that's accidentally sorted and do [25:23] something meaningful and you can [25:24] serialize that list to dis and read it [25:25] in and then do something very fast and [25:29] you could do this in C obviously but [25:30] you'd be inventing a lot of Wheels [25:32] python is just sort of there and yeah it [25:34] will be a little bit less efficient in [25:36] Python but the the overall structure the [25:38] overall order of magnitude of all the [25:40] computations is much lower and you know [25:43] yeah you'll pay a penalty python versus [25:44] C but overall you're doing the right [25:47] thing um a big thing about efficiency is [25:50] is obviously measurement and uh python [25:53] measurement is a little bit like t- [25:54] reading um I think you get you have to [25:57] get some experience before you're able [25:58] to make intuitive leaps and just when [26:00] you think you should do intuitive leaps [26:02] you can make them you shouldn't um [26:05] there's a lot of things in Python that [26:06] are counterintuitive cost of garbage [26:08] collection you know all sorts of things [26:11] like most of our app spends its time [26:13] most chunks of our app spend its time [26:16] serializing and profiling a serializer [26:20] you know it's a lot like a sewer like [26:21] what you put into it depends you know [26:22] what you get out of it depends on what [26:23] you put into it so if you set if you [26:26] test it with like a bag of ins and [26:28] normally you [26:29] know that's great synthetic data but [26:32] normally if you're you're putting 4K [26:34] Unicode blobs in there probably you [26:35] should have tested that because [26:37] guarantee you that's going to be [26:40] different so what are some you know what [26:43] are some ways that we we get efficiency [26:45] in Python [26:47] um Beyond like I've enumerated a few [26:50] libraries and I'll talk a little bit [26:51] about them but efficiency in Python is [26:54] more about knowing what not to do um [26:57] there's a lot of really powerful [26:58] metaprogramming things and how they [27:01] interact and how how Dynamic you make [27:03] things has a pretty direct correlation [27:06] to how expensive it is to run your [27:07] python app so uh dumb tends to turn out [27:10] to be fast so this is something that we [27:12] also we use a lot and it also it has [27:14] other side effects too Dumber code is [27:17] easier to GP for is easier to maintain [27:19] is easier to you know these are the kind [27:21] of tools that you know I'm an emac and [27:23] grep kind of kind of problem solver so [27:26] um the more magical code base is the [27:28] harder it is for me to decode how it's [27:30] actually functioning these are you know [27:32] these are important characteristics of a [27:34] really large [27:35] system um so libraries ones you've [27:38] probably heard of obviously curl um it [27:40] turns out that pretty much every version [27:42] of [27:42] HTTP uh client side libraries are awful [27:46] and curl is curl is the least awful and [27:49] it's it's pretty complicated to uh to [27:51] crack into but the performance is is [27:53] excellent uh you know for an HTTP server [27:56] we did a recent uh a recent project [27:58] where we swapped out one fairly major [28:00] protocol for an HTP implementation and [28:03] even though it was in Inc in in [28:06] pikl the amount of time we spent sending [28:09] stuff over the wire was nuts and we [28:11] actually ended up um ripping out ripping [28:14] out HTTP doing a direct socket thing [28:16] with with python and that ended up being [28:19] about uh on global CPU about 8% cheaper [28:24] um so you have to measure right [28:26] sometimes there are counterintuitive [28:27] things like this it turns out that HTTP [28:29] implementations the enveloping is just [28:31] really expensive [28:33] um other things uh Wise Guy Wise Guys [28:36] Are are fast CGI seret container thingy [28:40] and it's uh it's uh some C code and it's [28:43] some Process Management and prefork [28:46] code YouTube is not asynchronous [28:48] everything is blocking um YouTube also [28:51] thinks Apache is real Rockstar [28:53] technology and uh every request you [28:55] watch is actually uh [28:59] yeah every request you watch is is going [29:01] through aache at some level so just when [29:04] you think you have to swap out aache you [29:05] really don't um Spitfire is our [29:07] templating system if you've seen cheetah [29:09] you'll probably recognize a lot of [29:11] Spitfire uh it has an abstract syntax [29:14] tree internally so we can it lets us do [29:17] Transformations and some optimizations [29:20] that end up making a bit [29:22] faster serialization formats I could go [29:24] on for a long time about these but it [29:26] turns out no that no matter which one [29:27] you they're all expensive so you should [29:30] uh you should measure and [29:32] um yeah just just measure and don't use [29:35] pickle for things if it's going if it's [29:38] I don't think I should have to tell you [29:39] this but yeah don't use piggle we did [29:42] it's not a good [29:47] choice okay efficient tools um Apache [29:51] and P Apache I mean HTTP server uh Linux [29:54] I don't think it's any major shock that [29:56] we're running on Linux um [30:00] you know I I did some programming on BSD [30:01] and I I actually worked at Microsoft at [30:03] one point so I I have some Windows [30:05] Experience [30:07] um Linux is is good in terms of manholes [30:11] there's always a way to get in and see [30:12] how your system is behaving and the the [30:15] awesome thing about that is that no bad [30:17] no matter how bad your like the app is [30:20] that you've [30:21] written at some fundamental level the [30:23] resources it's consuming are explorable [30:25] with basic Linux tools so this is like a [30:27] super powerful thing when you're trying [30:28] to build a distributed system srace TCP [30:31] dump you know whatever um MySQL YouTube [30:34] uses a lot of MySQL stuff um when again [30:37] when you watch a video you're getting [30:38] data from MySQL you're getting a lot of [30:40] data from MySQL and um you know [30:44] sometimes we use it as relational [30:45] database and sometimes we use it more as [30:47] a as a blob store um again it's all [30:50] about tuning and and making choices and [30:52] how you organize your data but you know [30:54] anybody who sort of blind you tell [30:56] blindly tells you that my SQL [30:58] doesn't scale or doesn't do something [31:01] probably has not considered exactly how [31:03] to solve the problem um there are good [31:06] fits for my SQL and bad so it's it's a [31:08] good but it's a good [31:09] Tool uh this is a Shameless plug uh vest [31:12] is a new project that I'm working on uh [31:14] it's actually written in go and it's a [31:16] front end to my SQL and this does a lot [31:18] of query optimization on the Fly query [31:20] rewriting and does a lot of proxy and [31:24] stuff it's it's a long long project but [31:26] it we just actually finished our first [31:27] open source release of a subcomponent so [31:30] this is currently what serves every [31:32] YouTube database request um it's an RPC [31:35] system this is what I was citing when I [31:36] said HTTP turns out to be [31:38] slow uh zookeeper if zookeeper is the [31:41] lone piece of java software that makes [31:44] me think that Java might be [31:45] redeemable uh zookeeper is a distributed [31:49] sort of lock servery thing and it's uh [31:52] in some Dimensions that looks like a [31:54] very reliable file system and it's we [31:57] use it for configuration on a lot of [31:59] things it's really [32:01] uh it's a really interesting piece of [32:04] technology it's also like very hard to [32:07] understand how to use it correctly so [32:09] don't just bung things in there you have [32:10] to actually read the [32:12] manual [32:14] um so productivity [32:18] um these are sort of nebulous topics [32:20] what can I say I mean frankly I believe [32:23] more in philosophy than Doctrine like we [32:25] try to say like simple all right make it [32:26] simple what does that mean I don't know [32:29] but I'll know it when I see it like if [32:30] you come to me in your first code review [32:31] is you know thousands of lines and many [32:33] many files probably there was an easier [32:35] way for you to do it and and that's and [32:37] that's how I want you to to start and [32:39] you know your first demo should be [32:40] simple get it working then iterate [32:44] um my personal pet peeve is [32:46] documentation where people put like a [32:49] function R called video ID and then a [32:51] comment saying our colon video ID space [32:55] this is the video ID like great now I [32:58] lost like two lines of header two lines [33:00] you know I have a pretty small screen [33:02] and every line counts and this line I'm [33:04] going to guess let me tell you video ID [33:06] probably video ID please don't write [33:07] this again this may be a Minority Report [33:10] but this thing bothers the hell out of [33:12] me um so more conventions just you know [33:16] how do we organize code we frankly don't [33:18] do a lot of object-oriented programming [33:20] we do a lot of name spaces we have a lot [33:22] of uh you know in C this would be called [33:26] um I can't what it's called in C you [33:29] have the struck and you pass it in I [33:31] can't remember anyway we use we use [33:34] classes to organize data and we rarely [33:37] use them for objectoriented Stuff um [33:41] back when we started this project and [33:42] the and the previous company I worked at [33:44] which is also in Python um that was [33:47] relevant module level functions were a [33:49] lot faster now probably not so much the [33:51] case 26 has a lot of great caching um [33:55] I'm I'm sort of running out of time so [33:56] I'm going to zoom a little a little bit [33:58] and get right to questions which I think [34:00] will probably be more interesting than [34:01] me talking [34:04] um I don't know where I picked this [34:06] thing up but uh whenever I talk to some [34:08] some really smart dude I always feel [34:11] like what motivated this guy to make [34:13] these decisions that's more um that's [34:15] more what helps me make good decisions [34:17] than trying to actually repeat um what [34:19] he did so hopefully that's that's good [34:22] advice and uh so code bonsai was a a [34:26] sort of a wacko idea I came up with when [34:28] someone asked me to do a talk last year [34:31] and this is like what is what is your [34:32] code tree going to look like and these [34:35] are the words that I wanted people to to [34:37] use when they describe my code tree I [34:40] don't know if anybody looking at the [34:41] actual YouTube code tree would use too [34:42] many of these um but in my like falsely [34:46] idyllic world this is what it looks like [34:48] and and you know just to give you a [34:49] little visual visualization this is what [34:52] I'm hoping for right this is sort of [34:55] closer to reality um [34:59] yeah so let's just do questions and uh [35:03] and see how it [35:06] goes uh far [35:14] left uh if you can use the mic we can [35:17] start right here first person's the mic [35:20] go [35:23] okay uh if you could talk a little bit [35:24] about um the um YouTube CDN or any like [35:28] specific things that use there in terms [35:30] of uh first question is about the [35:31] YouTube CDN um very briefly so YouTube [35:35] uh originally contracted out some CDN [35:37] work for video and for image serving uh [35:39] this is of course psychotically [35:40] expensive and after uh some point it [35:43] makes sense to do it yourself um so it [35:46] turns out that you can build a pretty [35:48] good video CDN uh if you have a good [35:50] Hardware dude so you basically build a [35:52] very large rack stick a bunch of [35:54] machines in it put a good switch in then [35:56] take Lighty [35:58] and override the 404 Handler to be a [36:00] piece of python that knows where to find [36:01] the video that you didn't find uh that [36:03] took two weeks and on its first day [36:05] served 60 gigabits so uh that that was [36:10] the first incarnation of the YouTube CDN [36:12] uh your mileage may vary but you can you [36:15] can do a lot with really simple tools [36:17] that is all true uh next [36:20] question hi um first of all I just [36:23] wanted to say thanks a lot there was a [36:24] lot of stuff in here that we were [36:26] nodding about um our shop isn't quite at [36:28] your guys scale but we've been going [36:29] through a lot of these experiences over [36:31] the last couple years we're about 80 [36:32] million users now and have run into a [36:34] lot of the same things I also just [36:36] wanted wanted to actually tell you about [36:38] one thing there's a um we we were using [36:40] protocol buffers for doing lots of [36:42] passing and the python protocol buffer [36:44] library right on 23 sucks on 24 is like [36:48] experimental C++ bindings but they're [36:49] kind of unstable we wrote a replacement [36:52] that's all C with a thin layer it's [36:54] called palm and it's on GitHub come come [36:56] uh come talk to me [36:58] I have a feeling you might have been [36:59] kind of like spending we were spending [37:01] all our time seral serializing so anyway [37:04] so YouTube for a couple of massive [37:06] systems used it the question was Loosely [37:08] uh we're trying to use protocol buffers [37:10] are protocol buffers actually fast the [37:11] answer is kind of no but they're they're [37:14] going to get better um obviously this is [37:16] a big thing about measuring we use Bon [37:19] uh we have a bson implementation that we [37:21] wrote that is 10 15 times faster than [37:24] the one you can download we are open [37:26] sourcing it as part part of the vest [37:28] project um so we'll we'll give we'll [37:31] give back yeah that's interesting cuz we [37:33] used Mongo's beast and library for a [37:35] while too that was our replacement cuz [37:37] PBS weren't doing it so anyway cool [37:39] thanks we have enough time for one more [37:42] question try to keep it short if you can [37:44] thanks uh what would you say to those of [37:46] us that have The Misfortune of needing [37:47] to implement a new feature on a system [37:49] that's already receiving a lot of [37:50] traffic uh mirroring production traffic [37:52] or writing a good simulation of existing [37:54] production [37:55] traffic oh so the question is how do you [37:57] change the wheels while the car is [37:59] running um so yeah I mean I've done a [38:02] lot of large scale data migrations and [38:04] you know I mean every system is is [38:06] entirely different you know right now [38:08] when we do a big data migration we [38:10] frequently route some percentage of read [38:13] traffic and then the rights pretty much [38:15] have to be real sure that it's going to [38:16] go you run a simulation and cross your [38:19] fingers and and so far we haven't had [38:20] any major disasters but that's pretty [38:22] much the only recipe there is you know [38:23] you can't um you know you at some level [38:26] you make the decision on how you're [38:28] going to access one data pattern versus [38:30] the other um it's kind of a hard [38:31] question to answer without more context [38:33] about your app but hopefully that's [38:36] something all right thanks guys [38:41] [Applause]