60
REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART Reactive Retail Big Retail Goes Reactive at Walmart NOVEMBER 2014

Big Retail Goes Reactive at Walmart

  • Upload
    nurun

  • View
    796

  • Download
    3

Embed Size (px)

DESCRIPTION

Last year, Nurun and Walmart Canada launched the first responsively designed enterprise e-commerce website created for a large Canadian retailer. Built on a new platform with the Play Framework, Scala and Akka at its core, this foundation has proven itself in terms of flexibility, developer productivity, performance and scalability. We’ll share some of the insights we’ve gained in creating a best of breed solution that scales to Walmart’s needs—now and into the future.

Citation preview

Page 1: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Reactive Retail

Big Retail Goes Reactive at Walmart NOVEMBER 2014

Page 2: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Introduction Walmart.ca re-architecture Move to Functional Programming Technical Tips & Features Experiences and Impressions Outlook Q&A

Agenda

Page 3: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

About Nurun

12

Atlanta

Nancy

Shanghai

Quebec Turin

Montreal

Paris

Milan

Toronto

San Francisco

Chicoutimi

Madrid

1,200+ Employees

14 Years In Business

Retail

Automotive

Financial Services

Media & Entertainment

Fashion & Beauty

AREAS OF EXPERTISE

Utilities

Government

Telecommunications

Travel & Hospitality

Health & Pharma

3

We are a global design & technology consultancy with 12 offices worldwide.

Page 4: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Introduction

Page 5: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Introduction

TYPICAL LARGE ECOMMERCE ENVIRONMENTS

E-Commerce Platform

RDBMS

JSPs

Product content management

CDN

Page 6: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Introduction

TYPICAL LARGE ECOMMERCE ENVIRONMENTS

E-Commerce Platform Search &

merchandizing

RDBMS

JSPs

Product content management

CDN

Page 7: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Introduction

INCUMBENT PLATFORM

•  ATG, Oracle •  Fairly monolithic

•  Rapidly evolving merchandising needs

Page 8: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Introduction

INCUMBENT PLATFORM

•  ATG, Oracle •  Fairly monolithic

•  Rapidly evolving merchandising needs

Page 9: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Introduction

INCUMBENT PLATFORM

•  ATG, Oracle •  Fairly monolithic

•  Rapidly evolving merchandising needs

•  Scalability issues

Page 10: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Retail priorities

EFFICIENT & SCALABLE Need to handle large volumes RESILIENT Downtime is expensive FLEXIBLE & MAINTAINABLE Business requirements change

Page 11: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Need to go Reactive to be …

RESPONSIVE Customer experience, brand promise RESILIENT Handle failure at multiple levels ELASTIC Handle traffic spikes (without breaking the bank) MESSAGE-DRIVEN Enable all of the above  

Page 12: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Walmart.ca Re-architecture

Page 13: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Walmart.ca re-architecture

ATG

Oracle

Product content management

JSPs

Page 14: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Walmart.ca re-architecture

ATG

Oracle

REST API

Endeca search & merchandizing

REST API

Product content management

JSPs

Page 15: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Walmart.ca re-architecture

ATG

Oracle

Endeca search & merchandizing

REST API

Akka, Redis

Product content management

JSPs

Page 16: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Walmart.ca re-architecture

ATG

Oracle

Endeca search & merchandizing

REST API

Play

Akka, Redis

Product content management

JSON

JSPs

Page 17: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Walmart.ca re-architecture

ATG

Oracle

REST API

Endeca search & merchandizing

REST API

Play

Akka, Redis

Product content management

JSON JSON

Page 18: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Walmart.ca re-architecture

No. 1 +20%

+98%

Canada’s first responsively designed e-commerce site for a big box retailer

Increase in conversion in the first 4 weeks after launch

Increase in mobile orders

-36%

Decrease in average page load time

Awarded BEST E-COMMERCE SITE in large retailers by Retail Council of Canada

Page 19: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Walmart.ca re-architecture

No. 1 +20%

+98%

Canada’s first responsively designed e-commerce site for a big box retailer

Increase in conversion in the first 4 weeks after launch

Increase in mobile orders

-36%

Decrease in average page load time

NO SYSTEM OUTAGES!

Awarded BEST E-COMMERCE SITE in large retailers by Retail Council of Canada

Page 20: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Move to Functional Programming

Page 21: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Move to Functional Programming

● Majority of the team are developers with a Java background

● Play provides an easy entry path to Scala / Reactive / Functional:

§  Based on familiar MVC patterns

§  Can start with Java style, mutation, blocking

§  Incrementally transition to Scala style, immutable, non-blocking

Page 22: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Move to Functional Programming

1. No nulls (use Option)

2. No vars, mutable state*

3. Use higher-order functions (map, flatMap, filter, for-yield, etc.)

4. Business logic should be side-effect free (testability!)

5. Create and use strong types

*unless well justified (e.g. much clearer), and as small a scope as possible

Page 23: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Move to Functional Programming

●  Code should be a clear and concise as possible

●  Types should be express intent and fit tightly

Page 24: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Move to Functional Programming: Strong Types

sealed trait Language case object English extends Language

case object French extends Language def formatPrice(price: Price, lang: Language) = lang match {

case English => … case French => …

}

implicit val binder = new PathBindable[Language] {

… }

Page 25: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Technical Tips & Features

Page 26: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: Caching Futures (on-heap)

● Several concurrent requests for same data

● Whoever requests first initiates the Future (Promise)

● No locking required (narrow window between first request and when

Future is cached)

Page 27: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: Handling JSON

Play Application Makes Heavy Use of JSON

•  Consumes JSON view advice from Endeca

•  Proxy & augment JSON data for web service calls

Page 28: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: Play JSON macro

Consuming JSON (e.g. Endeca cartridges) case class Product(id: Long, name: String, …)

object Product {

implicit val formats = Json.format[Product] }

Json.toJson(product)

productJson.asOpt[Product]

Page 29: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: ‘Almost Default’ Reads/Writes

OPEN CHALLENGE

Sometime we want an ‘almost default’ Reads/Writes

•  e.g. use a default

•  Read/write a few fields in a particular way

•  e.g. format two dates in different ways

•  (Could Shapeless case class generics macro help?)

Page 30: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: Proxying and Augmenting JSON

Proxying JSON (e.g. most web services)

•  Might want to augment a JSON response

•  Don’t need to care about knowing the entire structure

•  Play JSON transformers

•  play-json-zipper can be helpful (github: mandubian)

Page 31: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: Dependency Injection

CONTROLLER DEPENDENCIES (SERVICES)

•  Use structural types for DI at the controller level

•  Create a services module for each request

•  Want access to request header (logging)

Page 32: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: Dependency Injection

THREADLOCAL

•  Inject dependencies in Global.getControllerInstance

•  Initialize services module in Global.onRouteRequest, add to

ThreadLocal

•  Pick up this value in the getControllerInstance and provide it to our

controller

Page 33: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: Monadic Rendering

Page Model

•  Template

•  Zones

•  Cartridges

Page 34: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Rendering View Advice: Templates & Zones

The business user selects a template:

•  Determines the page layout

•  Each template has ~12 zones

Page 35: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Rendering View Advice: Cartridges

… adds cartridges to the zones:

•  ~100 cartridges

ProductImage

ProductDescription

ProductPurchase

Page 36: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Rendering View Advice: Whole Page

•  Endeca fills in data (product info)

•  Play renders the cartridge as HTML

Page 37: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Rendering View Advice: JSON to Visual Page •  Tmpl1

•  Header •  Car1 •  Car2

•  LeftNav •  Car3

•  MainContent •  Car4 •  Car5 •  Car6

Page 38: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Rendering View Advice: JSON to HTML •  Tmpl1

•  Header •  Car1 •  Car2

•  LeftNav •  Car3

•  MainContent •  Car4 •  Car5 •  Car6

<body>! <div class=“header”>!! !…!

</div>! <div class=“leftNav”>!! !…!

</div>! !<div class=“main”>!! !…!

</div>!</body>!

Page 39: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Rendering View Advice: Auxiliary Information

•  Tmpl1 •  Header

•  Car1 •  Car2

•  LeftNav •  Car3

•  MainContent •  Car4 •  Car5 •  Car6

<head>!

!

</head>!

<body>!

<div class=“header”>!

! !…!

</div>!

<div class=“leftNav”>!

! !…!

</div>!

!<div class=“main”>!

! !…!

</div>!

!

!

</body>!

Page 40: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Rendering View Advice: Auxiliary Information

•  Tmpl1 •  Header

•  Car1 •  Car2

•  LeftNav •  Car3

•  MainContent •  Car4 •  Car5 •  Car6

<head>!

!

</head>!

<body>!

<div class=“header”>!

! !…!

</div>!

<div class=“leftNav”>!

! !…!

</div>!

!<div class=“main”>!

! !…!

</div>!

!

!

</body>!

CSS / JavaScript / RJS modules

Page 41: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Rendering View Advice: Auxiliary Information

•  Tmpl1 •  Header

•  Car1 •  Car2

•  LeftNav •  Car3

•  MainContent •  Car4 •  Car5 •  Car6

<head>!

!

</head>!

<body>!

<div class=“header”>!

! !…!

</div>!

<div class=“leftNav”>!

! !…!

</div>!

!<div class=“main”>!

! !…!

</div>!

!

!

</body>!

CSS / JavaScript / RJS modules

JavaScript / RJS modules

Page 42: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Rendering View Advice: Auxiliary Information

•  Tmpl1 •  Header

•  Car1 •  Car2

•  LeftNav •  Car3

•  MainContent •  Car4 •  Car5 •  Car6

<head>!

!

</head>!

<body>!

<div class=“header”>!

! !…!

</div>!

<div class=“leftNav”>!

! !…!

</div>!

!<div class=“main”>!

! !…!

</div>!

!

!

</body>!

CSS / JavaScript / RJS modules

JavaScript / RJS modules Cache control

Page 43: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Monadic Rendering: ValidatedBuilder Monad

ValidatedBuilder[X] •  “Parse/process” X •  ≅ Future[(X, Boolean, Resources)]

•  Error flag: • Determine if page should be cached

•  Front-end resources •  CSS • RequireJS modules •  JavaScript snippets (+ page location requirements)

Page 44: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Monadic Rendering: ValidatedBuilder Monad

ValidatedBuilder[X] •  map and flatMap handle combining and propagating validity and

front-end resources •  Code focuses on the essential task (JSON -> HTML) without clutter •  Error prone ‘plumbing’ is handled by the monad abstraction

Page 45: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Monadic Rendering: ValidatedBuilder Zone

val headerContent: VB[Seq[Cartridge]] = (viewAdvice \ “header”)

.as[Seq[JsValue]] // Seq[JsValue] .map(Cartridge.parse) // Seq[VB[Cartridge]]

.vbSeq // VB[Seq[Cartridge]]

Page 46: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Monadic Rendering: ValidatedBuilder Template

val template: VB[Template] = for { header <- headerContent : VB[Seq[Cartridge]]

leftNav <- leftNavContent …

templateResult <- CayenneTemplate(header, leftNav, …)

} yield templateResult

Page 47: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Monadic Rendering: ValidatedBuilder Page

for { content <- template.contents : Future[Template]

resources <- template.resources : Future[Resources] isCacheable <- template.isValid : Future[Boolean]

yield {

val result = template.render(resources) if (isCacheable)

result else

result.withHeaders(noCache: _*)

}

Page 48: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: Dynamic Configuration

•  Ops can make on the fly configuration changes

•  Enable/disable services and site features

•  Change endpoints

Page 49: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Tips & Features: Dynamic Configuration

•  Sends configuration delta to Play (JSON object)

•  Play verifies the change (initialize services module)

•  Each request sees a snapshot of the configuration

•  Uses standard Play HOCON API

Page 50: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Experience and Impressions

Page 51: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Experience and Impressions ● Never need to say “no” to a client due to technical limitations,

● Heavily concurrency / parallelism, with very little headaches,

● Aggressive refactorings are surprisingly easy (thank you strong types).

Page 52: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Outlook

Page 53: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Outlook

NEW BREED OF PRODUCTS Reactive core

Page 54: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Outlook

NEW BREED OF PRODUCTS Reactive core Middleware

Page 55: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Outlook

NEW BREED OF PRODUCTS Reactive core Middleware Omnichannel CE

Page 56: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Outlook

NEW BREED OF PRODUCTS Reactive core Middleware Omnichannel CE Streaming big data Machine intelligence

Page 57: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Outlook

NEW BREED OF PRODUCTS Reactive core Middleware Omnichannel CE Streaming big data Machine intelligence CMS

Page 58: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Outlook

NEW BREED OF PRODUCTS Reactive core Middleware Omnichannel CE Streaming big data Machine intelligence CMS BAAS REsponsiveSS

Page 59: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Outlook

NEW BREED OF PRODUCTS Reactive core Middleware Omnichannel CE Streaming big data Machine intelligence CMS BAAS REsponsiveSS In store tech, IoT…

Page 60: Big Retail Goes Reactive at Walmart

REACTIVE RETAIL BIG RETAIL GOES REACTIVE AT WALMART

Q & A

Ankur Mathur @anchormath Dana Harrington @danagharrington https://github.com/dana-harrington