Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Beyond REST - Coursera's API Evolution

Beyond REST - Coursera's API Evolution

I gave this presentation at the first annual GraphQL Summit (http://graphqlsummit.com/#Saeta), describing Coursera's API systems, and our lessons learned as we scaled to over 20 million global learners, 1.5k courses, and over a hundred partners. We discuss our successes and failures, relational algebra and an application of it to REST/JSON APIs, and finally our open source API framework called Naptime.

Avatar for Brennan Saeta

Brennan Saeta

October 26, 2016
Tweet

Other Decks in Programming

Transcript

  1. Beyond REST Coursera’s API Evolution Revisiting theoretical foundations to improve

    developer productivity. Brennan Saeta ! @bsaeta " saeta
  2. Problems • Number of courses grew rapidly • Product needs

    changed: • premium course certificates • specializations • multi-university collaborations. • Growing size of engineering team
  3. Scale matters! In many dimensions • Queries per second •

    Data set size • Engineers • Types in ontology
  4. Performance Requirements • Minimize data transfer across WAN • Minimize

    round trips Nice-to-have’s • Caching • ETag & Conditional Request Support • Binary Serialization
  5. Relational Algebra Meets REST/JSON APIs Projection: filter fields in response

    Selection: filter items in a collection Joins: related resources
  6. https://api.coursera.org/api/courses.v1?q=slug&slug=machine-learning response: { "elements": [ { "courseType": "v2.ondemand", "id": "Gtv4Xb1-EeS-ViIACwYKVQ",

    "name": "Machine Learning", "slug": "machine-learning" } ], "linked": {}, "paging": { "total": 1 } } request endpoint: /api/courses.v1 request query parameters: { "q": "slug", "slug": "machine-learning" }
  7. https://api.coursera.org/api/courses.v1?q=slug&slug=machine-learning &fields=primaryLanguages response: { "elements": [ { "courseType": "v2.ondemand", "id":

    "Gtv4Xb1-EeS-ViIACwYKVQ", "name": "Machine Learning", "slug": "machine-learning", "primaryLanguages": ["en"] } ], "linked": {}, "paging": { "total": 1 } } request endpoint: /api/courses.v1 request query parameters: { "q": "slug", "slug": "machine-learning", "fields": "primaryLanguages" }
  8. https://api.coursera.org/api/courses.v1?q=slug&slug=machine-learning &fields=instructorIds&includes=instructorIds response: { "elements": [ { "courseType": "v2.ondemand", "id":

    "Gtv4Xb1-EeS-ViIACwYKVQ", "name": "Machine Learning", "slug": "machine-learning", ”instructorIds": [1244] } ], "linked": { "instructors.v1": [ { "id": 1244, "name": "Andrew Ng" } ] }, "paging": { "total": 1 } } request endpoint: /api/courses.v1 request query parameters: { "q": "slug", "slug": "machine-learning", "fields": "instructorIds", "includes": "instructorIds" }
  9. https://api.coursera.org/api/courses.v1?q=slug&slug=machine-learning &fields=instructorIds,instructors.v1(title)&includes=instructorIds response: { "elements": [ { "courseType": "v2.ondemand", "id":

    "Gtv4Xb1-EeS-ViIACwYKVQ", "name": "Machine Learning", "slug": "machine-learning", "instructorIds": [1244] } ], "linked": { "instructors.v1": [ { "id": 1244, "name": "Andrew Ng", "title": "Associate Professor, Stanford University; Chief Scientist, Baidu; Chairman and Co-founder, Coursera" } ] }, "paging": { "total": 1 } } request endpoint: /api/courses.v1 request query parameters: { "q": "slug", "slug": "machine-learning", "fields": "instructorIds, instructors.v1(title)", "includes": "instructorIds" }
  10. Naptime Key Learnings • Leverage type safety, carefully • Collections

    of Key-Value pairs • Opinionated framework improves communication Principle: Optimize for developer productivity.
  11. Problems remained • Flattened representation difficult for clients • URL

    representation cumbersome • Auto-doc tools not useable
  12. Problems remained • Flattened representation difficult for clients GraphQL queries

    are easy to read, modify, and maintain • URL representation cumbersome GraphQL queries are easy to read, modify, and maintain • Auto-doc tools not useable GraphiQL supports auto-completion and inline documentation
  13. GraphQL Query: query { CoursesV1Resource { slug(slug: "machine-learning") { id

    } } } request endpoint: /api/courses.v1 request query parameters: { "q": "slug", "slug": "machine-learning" }
  14. request endpoint: /api/courses.v1 request query parameters: { "q": "slug", "slug":

    "machine-learning", "fields": "primaryLanguages" } GraphQL Query: query { CoursesV1Resource { slug(slug: "machine-learning") { id primaryLanguages } } }
  15. request endpoint: /api/courses.v1 request query parameters: { "q": "slug", "slug":

    "machine-learning", "fields": "instructorIds", "includes": "instructorIds" } GraphQL Query: query { CoursesV1Resource { slug(slug: "machine-learning") { id instructors: instructorIds { id } } } }
  16. request endpoint: /api/courses.v1 request query parameters: { "q": "slug", "slug":

    "machine-learning", "fields": "instructorIds, instructors.v1(title)", "includes": "instructorIds" } GraphQL Query: query { CoursesV1Resource { slug(slug: "machine-learning") { id instructors: instructorIds { id title } } } }
  17. Key Lessons Learned Carefully understand your problem Look to theory:

    stand on the shoulders of giants Plug into the ecosystem
  18. Thank you! Photo Credits: Trevor Wilson — https://unsplash.com/@clevertrevor Pablo Garcia

    Saldaña — https://unsplash.com/@pagsa_ Rob Bye — https://unsplash.com/@robertbye Eli Francis - https://unsplash.com/@elifrancis Ryan Hafney — https://unsplash.com/@ryanhafey Thank you: Bryan Kane & Coursera Colleagues