Frontend Services

@kenstruys

Yelp's Mission

Connecting people with great local businesses

Team Growth

Development

  • Write Code/Tests
  • Run Build/Tests
  • Code Review
  • Merge

Ship it

`99%`

Chance a Branch is Bug Free

`99% * 99% = 98%`

2 Bug Free Branches

`99%^30 = 74%`

30 Bug Free Branches

`99%^n`

`n > 500 = 0`

Monolithic Code Changes

yelp-main

  • Yelp's monolith
  • Mostly Python
  • MVC Sites
  • Offline batches

yelp-main 2011

  • 60 Engineers
  • 2 scheduled daily deploys
  • 5 - 8 changes per deploy

yelp-main 2011-2013

  • 60 → 200 Engineer
  • More products, code, tests
  • 3 scheduled daily deploys

Deployments Get Scary

  • 30+ changes per deploy
  • 50,000 Tests, 200 Selenium Tests
  • No one dev knows every error case
  • Rollbacks start to become common

Services Might Help

What is a Service?

  • Provides a service to other services
  • Often done via HTTP, Thrift, protobuff
  • Example: The Facebook API

How to Service

  • Usually a separate repository
  • Own set of tests
  • Own deployment
  • Backwards compatible
  • Share code via Libraries

What is a Library?

  • A collection of functions/classes/values
  • Have their own build/tests
  • Libraries can depend on other libraries
  • Multiple services can depend on libraries
  • Libraries are versioned
  • Example: jQuery

???

Yelp 2013

  • Backend Services
  • Monolith API
  • Everything New → Service

Backend Service Problems

Availability, Performance, Query Complexity


    def most_recent_review_for_user(user_id)

        business, review = DB.query('
            SELECT *
            FROM review
            JOIN user ON user.id=review.user_id
            JOIN business ON review.business_id=business.id
            WHERE user.id=${user_id}
            ORDER BY review.created
            LIMIT 1;
        ', user_id)

        return business, review

                    

You'll Need Frontend/Product Help

2014

Something Still Isn't Right...

Frontend Services

HTML Rendering Services

Frontend Isn't Easy Either

  • Very few talks about Frontend SOA
  • Keep Product Consistency
  • SOA Education

Where did we start?

  • Move fast, fail early
  • A page as a unit
  • Make it faster next time
  • Leverage existing SOA

git://services/styleguide

yelp.com/styleguide

git://services/styleguide

  • No backend
  • English only
  • Low Impact
  • Renders everything useful

How do we share code?

  • git://yelp-main
  • git://services/styleguide

PyPi + Bower


    > cat styleguide/bower.json
    {
        "name": "service-styleguide",
        "dependencies": {
            "jquery": "1.8.2",
            "yelp_styleguide": "0.10.3"
        }
    }
                    

    $ bower install
    ...
    bower jquery#1.8.2              install jquery#1.8.2
    bower yelp_styleguide#0.10.3    install yelp_styleguide#0.10.3
    ...

    $ tree bower_components/ -L 1
    bower_components/
    ├── jquery
    ├── yelp_styleguide
                    

yelp_styleguide

  • SCSS (underscored)
  • JavaScript
  • Images/Icons
  • Tests
  • bower.json

    @import "bower_components/yelp_styleguide/assets/scss/grid_layout";
                    

Releasing Styleguide Service

  • Trivial HTTP proxy in monolith
  • Delete all code/tests in monolith

Service Tips

Semantic Versioning

MAJOR.MINOR.PATCH

Example

  1. 1.8.2 → 1.8.3
  2. 1.8.5 → 1.9.3
  3. 1.9.1 → 2.0.0

Semver in Bower

  1. *
  2. 1.8 - 1.9
  3. ~1
  4. 1.9.2

Dep Management

Min Versions in Libraries


    > cat yelp_styleguide/bower.json
    {
        "name": "yelp_styleguide",
        "dependencies": {
            "jquery": ">=1.8",
        }
    }
                    

Build/Test Libraries Daily


On Failure:

  • Make your library compatible
  • ... or add a max version
  • Release a new version

Pin Deps in Services


    > cat styleguide/bower.json
    {
        "name": "service-styleguide",
        "dependencies": {
            "jquery": "1.8.2",
            "yelp_styleguide": "0.10.3"
        }
    }
                    

We Made Mistakes

Let's make a monolith!

30+ Pages Overnight

Thanks!

Questions?