Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/2xCHu90.
Aditya Modi and Karthik Ramgopal explore LinkedIn’s original ideas behind API modeling, the challenges they’ve faced, and how they are evolving their modeling strategy over time based on their learnings. They present a use case study of building the templated API behind LinkedIn’s new in-app notification experience. Filmed at qconnewyork.com.
Karthik Ramgopal is a Senior Staff engineer in the application infrastructure group, and leads the mobile infrastructure team at LinkedIn. Aditya Modi is a Staff Software Engineer in the Application Infrastructure team. He leads the infrastructure development for the front-end API server, which powers the LinkedIn app on iOS, Android and Web.
2. InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
linkedin-api-modeling
3. Presented at QCon New York
www.qconnewyork.com
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
19. Composite screens
● Two top level resources
■ Invitations
■ PYMK (People You May Know)
● 1 network call to fetch both resources
■ Infrastructure level aggregation support
20. • Easy to model
• Decouple API from UI
• Client side consistency
Advantages
28. Takes a long time to ship a feature
API Server
1.5 weeks
iOS
2 weeks
Android
2 weeks
Web
2 weeks
Total time
3.5 weeks=+
Use case: Introduce a new kind of notification
29. • Create new models for every feature
• Write code on each client platform
• Wait for native app release/adoption
Why so long?
46. How did we solve the AttributedString problem?
• Model formatted text
• Control formatting from the server
• Impractical to use HTML
AttributedString
47. AttributedString schema
AttributedString
● Text: String
● Attributes: List[Attribute] BOLD, ITALIC, UNDERLINE etc.
Attribute
● Type: AttributeType
● StartIndex: Int
● Length: Int
● Metadata: Any?
52. TextViewAttributeType
TextViewAttributeType
● PROFILE_FIRST_NAME
● PROFILE_FULL_NAME
● PROFILE_HEADLINE
● PROFILE_DISTANCE
● COMPANY_NAME
● COMPANY_HEADLINE
● JOB_TITLE
● ….
If a particular type is used, then the corresponding entity is populated by the server.
● PROFILE_XXX types will populate the profile field for example with the corresponding profile.
53. Backward compatibility++
Old clients cannot handle new mention types. Always send Raw text though redundant.
{
“title” : {
“Text”: “Sarah Clatterbuck shared this”,
“Attributes”: [
{“Type”: “PROFILE_FULL_NAME”,
“StartIndex”: 0….}
]
}
}
54. • Singular and Plurals
• Possessive forms
• i10n and i18n
Watch Out
55. How about images?
Use the same concept as TextViewModel. Introduce ImageViewModel.
ImageViewModel
● Attributes: List[ImageViewAttribute]
ImageViewAttribute
● ImageViewAttributeType
● URL: URL?
● ResourceName: String?
● Profile: Profile?
● Job: Job?
● Company: Company?
● Course: Course?
Flattened canonical entities as optional fields
56. ImageViewAttributeType
ImageViewAttributeType
● URL
● RESOURCE_NAME
● PROFILE_IMAGE
● PROFILE_BACKGROUND
● COMPANY_IMAGE
● ….
If a particular type is used, then the corresponding entity is populated by the server.
● PROFILE_XXX types will populate the profile field for example with the corresponding profile.
● URL type will populate the image URL
● RESOURCE_NAME will populate the pre-canned resource name.
57. Rendering Images
● Infra code extracts Image URL out of ImageViewModel
● Load into platform specific image view.
One Attribute: Regular ImageView
Multiple Attributes: GridImageView
58. Performance considerations
Entities may repeat multiple times within the same notification causing payload size bloat.
Tim’s Profile in ImageViewModel Tim’s Profile in TextViewModel
59. Solution: Response Normalization
All canonical entities have a unique ID. Use a JSON API like response format.
{
“data” : {
“Profile”: “profile:123”, ...
},
“included”: [
{
“id” : “profile:123”, “firstName” : “Tim”, “LastName” : “Jurka”, ... }
},
....
]
}
61. Solution: Deco
Deco is a LinkedIn framework that allows selective projection and decoration of fields.
Profile in TextViewModel
ID
FirstName
LastName
Profile in ImageViewModel
ID
ImageURL
Profile in Response
ID
FirstName
LastName
ImageURL
65. Code size reduction
15k LOC app and test code for old UI
3k LOC app and test code for new UI
66. Future Direction
● Extend to other pages in Flagship
● Extend to other LinkedIn apps like JobSeeker, Recruiter etc.
67. Out of scope for this talk
● Intricate details of client side consistency management
● Generic Modeling of actions
● Challenges in migrating from the old notifications API to the new one
Find us after the talk, and we’re happy to chat about this and more.