Share
Embed
Rapidly iterating across platforms using server-driven UI
Often companies with large mobile user bases find that they have to balance rapid iteration with the amount of work involved in launching and coordinating a product on multiple platforms (web, native Android, and native iOS).
Faced with exactly this question for the Airbnb reservation system, we designed a server-driven UI framework for web, iOS, and Android that allows us to launch new types of reservations on all platforms with a simple backend change. It uses a commonly shared API that is parsed on the client and rendered into a set of corresponding components supported on all platforms.
The talk also covers the ways other teams at Airbnb are using server-driven UI to do cross-platform product development.
Laura Kelly
June 26, 2018
Transcript
75 slides
-
• Android Engineer @ Airbnb • Previously front-end web •
Trip platform team • Powerlifter • Whiskey connoisseur @heylaurakelly Who I am -
1. The problem we were trying to solve 2. Why
server-driven UI fit the bill 3. Deep-dive into Android implementation 4. Case studies from Airbnb @heylaurakelly Outline -
Airbnb is adding new products all the time @heylaurakelly Homes
Experiences Restaurants -
@heylaurakelly Airbnb is adding new products all the time Homes
Experiences Restaurants Coworking Spaces -
@heylaurakelly Homes Experiences Restaurants Coworking Spaces We were rebuilding nearly
the same screen, multiplying our efforts across the codebase -
What is server-driven UI? { "type": "place", "id": "123", "rows":
[ { "type": "row:carousel", "image_urls": [ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] }, { "type": "row:map", "address": "1234 Main Street" } ] } Example API response @heylaurakelly -
@heylaurakelly { "type": "place", "id": "123", "rows": [ { "type":
"row:carousel", "image_urls": [ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] }, { "type": "row:map", "address": "1234 Main Street" } ] } API Response -
@heylaurakelly { "type": "place", "id": "123", "rows": [ { "type":
"row:carousel", "image_urls": [ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] }, { "type": "row:map", "address": "1234 Main Street" } ] } API Response -
@heylaurakelly API Response { "type": "place", "id": "123", "rows": [
{ "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } -
@JsonSubTypes({ @JsonSubTypes.Type( value = CarouselDataModel.class, name = “row:carousel” ), @JsonSubTypes.Type(
value = TitleRowDataModel.class, name = “row:title” ), @JsonSubTypes.Type( value = ActionRowDataModel.class, name = “row:action" ) . . . }) { "type": "place", "id": "123", "rows": [ { "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } @heylaurakelly Map to Data Models API Response -
@heylaurakelly export default { 'row:carousel': CarouselRow, 'row:title': TitleRow, 'row:action': ActionRow,
. . . } Frontend Web Code { "type": "place", "id": "123", "rows": [ { "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } API Response -
@JsonSubTypes({ @JsonSubTypes.Type( value = CarouselDataModel.class, name = “row:carousel” ), @JsonSubTypes.Type(
value = TitleRowDataModel.class, name = “row:title” ), @JsonSubTypes.Type( value = ActionRowDataModel.class, name = “row:action" ) . . . }) Map to Data Models { "type": "place", "id": "123", "rows": [ { "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } API Response UI Rendering @heylaurakelly -
@heylaurakelly @JsonSubTypes({ @JsonSubTypes.Type( value = CarouselDataModel.class, name = “row:carousel” ),
@JsonSubTypes.Type( value = TitleRowDataModel.class, name = “row:title” ), @JsonSubTypes.Type( value = ActionRowDataModel.class, name = “row:action" ) . . . }) Map to Data Models { "type": "place", "id": "123", "rows": [ { "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } API Response UI Rendering -
@JsonSubTypes({ @JsonSubTypes.Type( value = CarouselDataModel.class, name = “row:carousel” ), @JsonSubTypes.Type(
value = TitleRowDataModel.class, name = “row:title” ), @JsonSubTypes.Type( value = ActionRowDataModel.class, name = “row:action" ) . . . }) Map to Data Models { "type": "place", "id": "123", "rows": [ { "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } API Response UI Rendering @heylaurakelly -
@JsonSubTypes({ @JsonSubTypes.Type( value = CarouselDataModel.class, name = “row:carousel” ), @JsonSubTypes.Type(
value = TitleRowDataModel.class, name = “row:title” ), @JsonSubTypes.Type( value = ActionRowDataModel.class, name = “row:action" ) . . . }) Map to Data Models { "type": "place", "id": "123", "rows": [ { "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } API Response UI Rendering @heylaurakelly -
@JsonSubTypes({ @JsonSubTypes.Type( value = CarouselDataModel.class, name = “row:carousel” ), @JsonSubTypes.Type(
value = TitleRowDataModel.class, name = “row:title” ), @JsonSubTypes.Type( value = ActionRowDataModel.class, name = “row:action" ) . . . }) Map to Data Models { "type": "place", "id": "123", "rows": [ { "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } API Response UI Rendering Carousel Title Row Action Row Rendering Framework @heylaurakelly -
@JsonSubTypes({ @JsonSubTypes.Type( value = CarouselDataModel.class, name = “row:carousel” ), @JsonSubTypes.Type(
value = TitleRowDataModel.class, name = “row:title” ), @JsonSubTypes.Type( value = ActionRowDataModel.class, name = “row:action" ) . . . }) Map to Data Models { "type": "place", "id": "123", "rows": [ { "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } API Response UI Rendering Title Row Action Row Rendering Framework Map Row @heylaurakelly -
@JsonSubTypes({ @JsonSubTypes.Type( value = CarouselDataModel.class, name = “row:carousel” ), @JsonSubTypes.Type(
value = TitleRowDataModel.class, name = “row:title” ), @JsonSubTypes.Type( value = ActionRowDataModel.class, name = “row:action" ) . . . }) Map to Data Models { "type": "place", "id": "123", "rows": [ { "type": "row:carousel", "image_urls":[ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] } ... ] } API Response UI Rendering Action Row Title Row Rendering Framework Map Row @heylaurakelly -
1. JSON from server JSON 2. Parse network response ArrayList<Row>
rows( ) @heylaurakelly -
1. JSON from server JSON 2. Parse network response 3.
Parse row subtypes ArrayList<Row> rows( ) LinkRow MapRow TitleRow HostAvatarRow @heylaurakelly -
1. JSON from server JSON 2. Parse network response 3.
Parse row subtypes 4. Configure UI models ArrayList<Row> rows( ) LinkRow MapRow TitleRow HostAvatarRow ReservationController ReservationFragment @heylaurakelly -
1. JSON from server JSON ReservationController ReservationFragment 2. Parse network
response 3. Parse row subtypes 4. Configure UI models ArrayList<Row> rows( ) LinkRow MapRow TitleRow HostAvatarRow 5. Render components @heylaurakelly -
1. JSON from server JSON 2. Parse network response 3.
Parse row subtypes 4. Configure UI models ArrayList<Row> rows( ) LinkRow MapRow TitleRow HostAvatarRow 5. Render components ReservationController ReservationFragment @heylaurakelly -
@AutoValue @JsonDeserialize(builder = AutoValue_Reservation.Builder.class) public abstract class Reservation { @JsonProperty
public abstract String primary_key(); @JsonProperty public abstract ArrayList<RowDataModel> rows(); ... } @heylaurakelly 2. Parse network response -
@AutoValue @JsonDeserialize(builder = AutoValue_Reservation.Builder.class) public abstract class Reservation { @JsonProperty
public abstract String primary_key(); @JsonProperty public abstract ArrayList<RowDataModel> rows(); ... } @heylaurakelly 2. Parse network response -
JSON ArrayList<Row> rows( ) LinkRow MapRow TitleRow HostAvatarRow 1. JSON
from server 2. Parse network response 3. Parse row subtypes 4. Configure UI models 5. Render components ReservationController ReservationFragment @heylaurakelly -
@heylaurakelly @JsonTypeInfo(...) @JsonSubTypes({ @JsonSubTypes.Type(value = LinkRowDataModel.class, name = "row:link"), @JsonSubTypes.Type(value
= MapRowDataModel.class, name = "row:map"), @JsonSubTypes.Type(value = TitleRowDataModel.class, name = “row:title”), @JsonSubTypes.Type(value = HostAvatarRowDataModel.class, name = “row:host_avatar”) ... }) public interface RowDataModel extends Parcelable { ... } 3. Parse row subtypes -
@heylaurakelly @JsonTypeInfo(...) @JsonSubTypes({ @JsonSubTypes.Type(value = LinkRowDataModel.class, name = "row:link"), @JsonSubTypes.Type(value
= MapRowDataModel.class, name = "row:map"), @JsonSubTypes.Type(value = TitleRowDataModel.class, name = “row:title”), @JsonSubTypes.Type(value = HostAvatarRowDataModel.class, name = “row:host_avatar”) ... }) public interface RowDataModel extends Parcelable { ... } 3. Parse row subtypes -
@heylaurakelly @JsonTypeInfo(...) @JsonSubTypes({ @JsonSubTypes.Type(value = LinkRowDataModel.class, name = "row:link"), @JsonSubTypes.Type(value
= MapRowDataModel.class, name = "row:map"), @JsonSubTypes.Type(value = TitleRowDataModel.class, name = “row:title”), @JsonSubTypes.Type(value = HostAvatarRowDataModel.class, name = “row:host_avatar”) ... }) public interface RowDataModel extends Parcelable { ... } 3. Parse row subtypes -
@heylaurakelly @JsonTypeInfo(...) @JsonSubTypes({ @JsonSubTypes.Type(value = LinkRowDataModel.class, name = "row:link"), @JsonSubTypes.Type(value
= MapRowDataModel.class, name = "row:map"), @JsonSubTypes.Type(value = TitleRowDataModel.class, name = “row:title”), @JsonSubTypes.Type(value = HostAvatarRowDataModel.class, name = “row:host_avatar”) ... }) public interface RowDataModel extends Parcelable { ... } 3. Parse row subtypes -
@heylaurakelly @AutoValue @JsonDeserialize(builder = AutoValue_LinkRowDataModel.Builder.class) @JsonTypeName("row:link") public abstract class LinkRowDataModel
implements RowDataModel { @JsonProperty public abstract String id(); @JsonProperty public abstract String title(); @JsonProperty public abstract String app_url(); @JsonProperty public abstract String loggingId(); ... } 3. Parse row subtypes -
@heylaurakelly @AutoValue @JsonDeserialize(builder = AutoValue_LinkRowDataModel.Builder.class) @JsonTypeName("row:link") public abstract class LinkRowDataModel
implements RowDataModel { @JsonProperty public abstract String id(); @JsonProperty public abstract String title(); @JsonProperty public abstract String app_url(); @JsonProperty public abstract String loggingId(); ... } 3. Parse row subtypes -
@heylaurakelly @AutoValue @JsonDeserialize(builder = AutoValue_LinkRowDataModel.Builder.class) @JsonTypeName("row:link") public abstract class LinkRowDataModel
implements RowDataModel { @JsonProperty public abstract String id(); @JsonProperty public abstract String title(); @JsonProperty public abstract String app_url(); @JsonProperty public abstract String loggingId(); ... } 3. Parse row subtypes -
JSON ArrayList<Row> rows( ) LinkRow MapRow TitleRow HostAvatarRow 1. JSON
from server 2. Parse network response 3. Parse row subtypes 4. Configure UI models 5. Render components ReservationController ReservationFragment @heylaurakelly -
Render with Epoxy HTTPS://GITHUB.COM/AIRBNB/EPOXY Open source library for building complex
screens in a RecyclerView -
@heylaurakelly class ReservationEpoxyController : TypedAirEpoxyController<Reservation>() { ... private fun RowDataModel.buildModel()
{ when (this) { is LinkRowDataModel -> buildModel() is MapRowDataModel -> buildModel() is TitleRowDataModel -> buildModel() is HostAvatarRowDataModel -> buildModel() } } } 4. Configure UI Models with Epoxy -
@heylaurakelly class ReservationEpoxyController : TypedAirEpoxyController<Reservation>() { ... private fun LinkRowDataModel.buildModel()
= basicRow { id([email protected]()) title(title()) onClickListener(navigationContoller.navigateToDeeplink(app_url())) } } 4) Configure UI Models with Epoxy -
JSON ArrayList<Row> rows( ) LinkRow MapRow TitleRow HostAvatarRow 1. JSON
from server 2. Parse network response 3. Parse row subtypes 4. Configure UI models 5. Render components ReservationController ReservationFragment @heylaurakelly -
{ "type": "place", "id": "123", "rows": [ { "type": "row:carousel",
"image_urls": [ "sightglassImage.png” ] }, { "type": “row:title“, "title": "Sightglass Coffee", "starts_at": “Sun, Sept 24, 7:00 PM" }, { "type": "row:action", "actions": [ /* ... actions here */ ] }, { "type": "row:map", "address": "1234 Main Street" } ] } @heylaurakelly -
Wall-E JSON Payload Components Ordered list of screens Includes conditions
for validation Questions Includes conditions for validation Answers Can be pre- populated, previously answered, or empty @heylaurakelly -
• A unified format for describing views • Can be
used standalone to natively parse and render pages • Can also underlie existing server-driven systems Lona Dynamic UI @heylaurakelly -
• API design is key • Think about platform differences
early on • Know how server-driven you want to go Tips for building a server-driven system @heylaurakelly -
Thanks @heylaurakelly Reservations contributors Laura Kelly, Eric Horacek, Tyler Hedrick,
Jenn Tilton, Callie Callaway, Laura Xu, Andy Bartholomew Wall-E contributors Truman Cranor, Kevin Almanza, Garrett Berg, Josh Freeman, Steven Liu, Chris Talley, Noah Hendrix Lona Dynamic UI contributors Nathanael Silverman, Kieraj Mumick, Devin Abott, Gabe G'Sell