scaling with swagger
DESCRIPTION
Ways you can scale your software and organization with Wordnik's Swagger frameworkTRANSCRIPT
Scaling with Swagger
Tony Tam@fehguy
Scaling is the Developer's Job
Was:
•Write code, make it work
•If it get slow, buy:
• Bigger server
• Bigger database
• "Enterprise" software support
Needs Harmony Between
•Software
•Data Tier
•Development Infrastructure
•Deployment Infrastructure
•Team
•Ability to manage it all
Needs Harmony Between
•Software
•Data Tier
•Development Infrastructure
•Deployment Infrastructure
•Team
•Ability to manage it all Best Achieved with Good
Architecture
Background
DBA
Data Tier
BizTier
"Been
Here"
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"
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!"
Solutions
•Many Possible
• Some suck, some good
•Let's look at Wordnik
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*
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
Vertical, Explained
•Big application => micro services
Monolithic application
"Isn't this just SOA?"
Not SOA
•This is different
• No proprietary message bus
• Decoupled objects
• Dedicated storage***
•Speak REST
• Develop your services in…
• Java
• Scala
• Ruby
• Php
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…
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!
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
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!”
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
What is this Resource Declaration?
•Each api is documentedhttp://petstore.swagger.wordnik.com/api/pet.json
API Documentation Highlights
•Describes
• Operations
• Models
•Permission-based filtering
•JSON and XML supported
Anatomy of API Documentation
Anatomy of API Documentation
Based on JSON
Schema (Draft)
http://tools.ietf.org/html/draft-zyp-json-schema-03
API Parameters
API Parameters
•Filtering on parameters
•Enumerated options w/optional default
API Parameters
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?
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?
Example Codegen
./bin/generate-scala-lib.sh \
http://petstore.swagger.wordnik.com/api \
"" \
"com.wordnik" \
client
Example Invocation
Scala
Ruby
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
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
Websockets to the Rescue!
•It's…
• Full Duplex
• Persistent connections
• Completely Async
•But…
• Very finicky
• Wildly inconsistent server support
• Still in draft
Websockets to the Rescue!
•It's…
• Full Duplex
• Persistent connections
• Completely Async
•But…
• Very finicky
• Wildly inconsistent server support
• Still in draft
Abstracted by Atmosphere
https://github.com/Atmosphere/atmosphere
•Fully Sponsored by Wordnik
•Abstracts the mess
•Support on many containers
•Client fallback/draft protocol support
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
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
Swagger Sockets
•Live now on smartmoney.com
•Fully OSS
•Wire-protocol speed
•Format-agnostic
• JSON
• Binary
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
See More…
•http://swagger.wordnik.com/
•https://github.com/wordnik/swagger-core
•https://github.com/wordnik/swagger-ui
•https://github.com/wordnik/wordnik-oss
Questions?