39
Scaling with Swagger Tony Tam @fehguy

Scaling with swagger

Embed Size (px)

DESCRIPTION

Ways you can scale your software and organization with Wordnik's Swagger framework

Citation preview

Page 1: Scaling with swagger

Scaling with Swagger

Tony Tam@fehguy

Page 2: Scaling with swagger

Scaling is the Developer's Job

Was:

•Write code, make it work

•If it get slow, buy:

• Bigger server

• Bigger database

• "Enterprise" software support

Page 3: Scaling with swagger

Needs Harmony Between

•Software

•Data Tier

•Development Infrastructure

•Deployment Infrastructure

•Team

•Ability to manage it all

Page 4: Scaling with swagger

Needs Harmony Between

•Software

•Data Tier

•Development Infrastructure

•Deployment Infrastructure

•Team

•Ability to manage it all Best Achieved with Good

Architecture

Page 5: Scaling with swagger

Background

DBA

Data Tier

BizTier

"Been

Here"

Page 6: Scaling with swagger

Common Mistakes…

•"Let's organize by horizontal!"

•"Back end shouldn't care what front end does!"

•"Just get it launched and we'll scale with hardware"

•"You can scale transparently with technology X"

•"Get an Oracle consultant to speed things up"

Page 7: Scaling with swagger

Common Problems

•Overly complicated interfaces

• Abstracted too many times

• "We can switch out entities with a simple configuration!"

•Over-abstracted

• "We might need to change database vendors so abstract the SQL layer"

•Over designed

• "We don't know how the client will call, so support all possible calls!"

Page 8: Scaling with swagger

Solutions

•Many Possible

• Some suck, some good

•Let's look at Wordnik

Page 9: Scaling with swagger

Directionally Speaking

•Go Vertical!

• Ability to understand full lifecycle

• APIs as the communication of choice

• General convergence on developers

• Databases (MongoDB, Cassandra, Dynamo)

• API frameworks

•IT & QA are disappearing

• Wordnik currently has *none*

• Team, infrastructure, discipline *win*

Page 10: Scaling with swagger

Directionally Speaking

•Go Vertical!

• Ability to understand full lifecycle

• APIs as the communication of choice

• General convergence on developers

• Databases (MongoDB, Cassandra, Dynamo)

• API frameworks

•IT & QA are disappearing

• Wordnik currently has *none*

• Team, infrastructure, discipline *win*

Still Room to

specialize

Page 11: Scaling with swagger

Vertical, Explained

•Big application => micro services

Monolithic application

"Isn't this just SOA?"

Page 12: Scaling with swagger

Not SOA

•This is different

• No proprietary message bus

• Decoupled objects

• Dedicated storage***

•Speak REST

• Develop your services in…

• Java

• Scala

• Ruby

• Php

Page 13: Scaling with swagger

All valid

!

Speak REST?

•Sounds good but…

• REST semantics vary wildly

• HATEOAS vs. practical REST?

/api/pet.json/1?delete (GET)

/api/pet.json/1 (DELETE)

/api/pet.json/1 (POST empty)

So…

Page 14: Scaling with swagger

All valid

!

Speak REST?

•Sounds good but…

• REST semantics vary wildly

• HATEOAS vs. practical REST?

/api/pet.json/1?delete (GET)

/api/pet.json/1 (DELETE)

/api/pet.json/1 (POST empty)

So…API

Styleguide!

Peer Review!

Better Docs!

API Council!

Page 15: Scaling with swagger

Hello, Swagger

•Swagger is…

• Spec for declaring an API schema

• A framework for auto-generating the spec

• A library for client library generation

• A JSON-based test framework

Page 16: Scaling with swagger

What is this Resource Declaration?

•Listing of all available APIshttp://petstore.swagger.wordnik.com/api/resources.json

“It’s like a sitemap for your

API!”

Page 17: Scaling with swagger

What is this Resource Declaration?

•“But I don’t want it all exposed!”

• Swagger can filter APIs by permissions

Header,URL,

Method

Api key,Cookies,OAuth

Page 18: Scaling with swagger

What is this Resource Declaration?

•Each api is documentedhttp://petstore.swagger.wordnik.com/api/pet.json

Page 19: Scaling with swagger

API Documentation Highlights

•Describes

• Operations

• Models

•Permission-based filtering

•JSON and XML supported

Page 20: Scaling with swagger

Anatomy of API Documentation

Page 21: Scaling with swagger

Anatomy of API Documentation

Based on JSON

Schema (Draft)

http://tools.ietf.org/html/draft-zyp-json-schema-03

Page 22: Scaling with swagger

API Parameters

Page 23: Scaling with swagger

API Parameters

•Filtering on parameters

•Enumerated options w/optional default

Page 24: Scaling with swagger

API Parameters

Page 25: Scaling with swagger

How does this help?

•Generate client libs

•Invoke methods not URLs

•Pass arguments, not query params

•Don't care about how service is developed

• Different versions of java?

• Different REST frameworks?

Page 26: Scaling with swagger

How does this help?

•Generate client libs

•Invoke methods not URLs

•Pass arguments, not query params

•Don't care about how service is developed

• Different versions of java?

• Different REST frameworks?

Scalatra

JAX-RS

Play!Client doesn't care

RESTler?

Page 27: Scaling with swagger

Example Codegen

./bin/generate-scala-lib.sh \

http://petstore.swagger.wordnik.com/api \

"" \

"com.wordnik" \

client

Page 28: Scaling with swagger

Example Invocation

Scala

Ruby

Page 29: Scaling with swagger

But What about Speed?

•Yes! REST over HTTP is slow

• Connection overhead

• Marshaling & Unmarshaling overhead

• Chatter

• JSON/XML need to diet

•It's also…

• Synchronous

• GET/POST/PUT/DELETE don't cut it

Page 30: Scaling with swagger

But What about Speed?

•Yes! REST over HTTP is slow

• Connection overhead

• Marshaling & Unmarshaling overhead

• Chatter

• JSON/XML need to diet

•It's also…

• Synchronous

• GET/POST/PUT/DELETE don't cut it

Your prod Database isn't doing

REST

Page 31: Scaling with swagger

Websockets to the Rescue!

•It's…

• Full Duplex

• Persistent connections

• Completely Async

•But…

• Very finicky

• Wildly inconsistent server support

• Still in draft

Page 32: Scaling with swagger

Websockets to the Rescue!

•It's…

• Full Duplex

• Persistent connections

• Completely Async

•But…

• Very finicky

• Wildly inconsistent server support

• Still in draft

Page 33: Scaling with swagger

Abstracted by Atmosphere

https://github.com/Atmosphere/atmosphere

•Fully Sponsored by Wordnik

•Abstracts the mess

•Support on many containers

•Client fallback/draft protocol support

Page 34: Scaling with swagger

Abstracted by Atmosphere

https://github.com/Atmosphere/atmosphere

•Fully Sponsored by Wordnik

•Abstracts the mess

•Support on many containers

•Client fallback/draft protocol support

Jetty

Tomcat

Netty Glassfish

Weblogic

JBoss Resin

Page 35: Scaling with swagger

Swagger + Websockets

•Swagger sockets

• Same discovery interface

• Same client interface

• Same codegen

•But…

• Multiplexed connections

• Support for binary protocol

• Full Async

• Adding "subscribe" to GET/POST/PUT/DELETE

Page 36: Scaling with swagger

Swagger Sockets

•Live now on smartmoney.com

•Fully OSS

•Wire-protocol speed

•Format-agnostic

• JSON

• Binary

Page 37: Scaling with swagger

Summary

•Smaller, dedicated units of work

•Micro services => micro teams

•Full service knowledge

•Swagger is the Fabric for your Services

•Swagger sockets are like Fiber for your grid's connectivity

Page 39: Scaling with swagger

Questions?