serverless journey of shop.lego - amazon web services€¦ · serverless journey of shop.lego.com...

67
serverless journey of shop.LEGO.com sheen brisals LEGO

Upload: others

Post on 20-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

serverless

journey of

shop.LEGO.com

sheen brisalsLEGO

Page 2: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo
Page 3: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

talk focus➢ reasons for the change

➢ high level architecture

➢ core principles

➢ overall process

➢ tools & techniques ➢ best practices

➢ development examples ➢ lessons

➢ what next?

Page 4: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

why change?

Page 5: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

BF-CM 2017

Page 6: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

decouple

Page 7: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

post BF-CM 2017

Page 8: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

BF-CM 2018

Page 9: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

operational reasons

• aging e-commerce platform

• release nightmare

• delayed features and fixes

• monolith

• tightly coupled dependencies

• limited scalability

• on premisis

Page 10: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

business needs

• market expansion

• consumer experience

• scalable platform

• fast turnaround

• automation

• modernise

• data driven

Events

PAB

Site map

Pricing

Products

Stores

Promotions

Customer

Wish list

Payments

Prices

VIP

Discounts

Orders

Address

BAP

Cart

Page 11: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

principles

Page 12: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

➢ cloud & AWS

➢ serverless

➢ managed services

➢ API based

➢ decouple dependencies

Page 13: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

architecture

Page 14: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo
Page 15: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

set piece architecture development

A Set Piece Architecture requires planning and execution, but

can be rehearsed in advance

Tax

Import/Export

Data Stream

Page 16: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

process

Page 17: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

two phase development

Nov ‘18 May ‘19July ‘18

• ImpEx

• Product Description

• Product Contents

• Sales Tax

• Data Layer

• Checkout

• Payments

• Orders

• Customer

• VIP

• Promotions

Page 18: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

agile and scrum

• practical agile if not text book style

daily standup

retro

planning

grooming

review• JIRA

• 2 week sprints

Page 19: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

focus squads

services

checkout content

infra

management

• 4 focus areas

• change and adapt

• squad autonomy

• business analyst

• product owner

• delivery manager

• director

Page 20: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

devops and automation

• not just programming

• embrace AWS & cloud

• shared responsibility with infra

• build, deploy & run culture

Page 21: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

dev, qa, prod accounts

• single sign on

• ease of use

• cost control

• access separation

• fits well with CI/CD

Page 22: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

design - review - decide

design

review

agree

develop

• decide quickly

• bold approach

• open for ideas

• change as needed

Page 23: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

solution detailing

• detail the design

• do PoC if needed

• input from engineers

• change as needed

Page 24: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

implement with tests• started off with units tests

• shared with QA

• integration tests now mandatory

• crucial for CI/CD pipeline

Page 25: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

CI - CD• PR merge triggers CI

• builds tests and deploys to QA

Submit PR Code AnalysisPush to GIT

QA Tests

Unit Tests

IntegrationQA

• production deploy is separate pipeline at the moment

Page 26: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

tools

techniques

Page 27: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

javascript

• existing skills

• javascript vs Golang

• popularity

• framework support

const handler = NewRelic.monitorLambda(async (event, context, callback) =>

{

log.initDefaultParams(context);

let response;

try {

const country = get(event, 'queryStringParameters.country');

validateRequest(country);

const client = creatorWithToken(event.headers.Authorization);

let cart;

cart = await getCurrentCartForUserByCountry(client, country);

if (cart) {

cart = await recalculateCart(client, cart);

} else {

cart = await createMyCart(client, country, CartType.STANDARD);

}

response = createResponse(200, cart);

} catch (e) {

response = handleError(e);

}

callback(null, response);

});

Page 28: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

serverless framework

• quick to get going

• easy of use

• popularity

• good plugins

• CloudFormation support

Page 29: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

GitHub & mono repo

• independent service

deploy pipeline

• package per service

Page 30: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

CircleCI

• not perfect but improving

• no auto deploy to production yet

Page 31: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

best practices

Page 32: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

cost awareness

requests cost + compute cost

requests cost + data transfer + cache

read (consistent/eventual) + write

(normal/transactional) + storage +others

Page 33: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

built-in & managed services

use lambda triggers – S3, SQS, SNS,…

avoid lambda if not needed for integration

use TTL to expire unwanted data

use life cycle policies effectively

Page 34: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

security - secure it

granular level policies

Page 35: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

functions:

vip-crt-status-check:

name: ${self:service}-crt-status-check-${self:provider.stage}

handler: functions/statusCheck/statusCheck.handler

memorySize: 256

timeout: 6

environment:

….

iamRoleStatements:

- Effect: Allow

Action:

- ssm:GetParameters

Resource:

-…. :_common.PARAMETER_NAME_CRT_API_KEY}

- …. :_common.PARAMETER_NAME_CRT_TEST_USER_ID}

- …. :parameter/vip/crt/status/*

- Effect: Allow

Action:

- ssm:PutParameter

Resource:

-…. :_common.PARAMETER_NAME_CRT_API_STATUS}

- …. :_common.PARAMETER_NAME_CRT_POS_STATUS}

Page 36: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

security - secure it

granular level policies api keys, lambda auth, usage plan

creds in Parameter Store secrets manager

S3 signed url item attribute level permission

Page 37: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

log, trace & monitor

use CloudWatch logs add traceability in logs

enable CloudTrail

setup alerts and alarms monitor everything

elasticsearch

Page 38: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

engineering

language choice code quality

develop & optimise be open for ideas

communicate collaborate co-locate

start-up mentality start small, scale fast

Page 39: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

set piece development

examples

Page 40: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

product - impex

Page 41: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

product - impex

Product Feeds Commerce PlatformFeed Messages

Page 42: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

product - impex

Product Feeds New PlatformTransform Feeds

Page 43: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

impex – design considerations

• feeds in JSON format

• failure re-try process

• decoupled processing

• failure notification

• immediate handling of feeds

• independent feed flow

Page 44: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

impex

Page 45: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

impex

Page 46: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

impex

Page 47: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

data layer aka event streaming

Page 48: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

event stream

Page 49: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

events – design considerations

• low cost

• support different event types

• ability to add new consumers and producers

• near realtime processing

under a minute

• highly available

• event data in JSON

Page 50: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

events

Page 51: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

events{

"commerce_event":["service-data-layer-recsengine-STAGE","service-data-layer-newrelic-STAGE","service-data-layer-optimizely-STAGE"

],"page_event":[

"service-data-layer-recsengine-STAGE","service-data-layer-optimizely-STAGE"

],"recs_event":[

"service-data-layer-recsengine-STAGE"]

}

Page 52: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

event stream

Page 53: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

lessons - team

Page 54: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

laydown the principles

• crucial to move

forward and

stick together

as a team

Page 55: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

sensible solution

• start simple and

evolve

• listen, learn,

improve

Page 56: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

be cost aware

• serverless is not free

• educate the team

• optimise

Page 57: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

proof of concept (PoC)

• builds confidence

• hands-on learning

• stakeholder showcase

Page 58: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

act fast

• agree & act

• just do it!

• small steps but faster

Page 59: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

lessons - aws

Page 60: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

monitor & optimise lambdas

Duration: 54908.63 ms Billed Duration: 55000 ms

Memory Size: 2048 MB Max Memory Used: 265 MB

Page 61: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

don’t keep (pay for) unwanted data• S3 lifecycle policies • CloudWatch - retire logs

• use DynamoDB TTL • SQS / DLQ storage retension

Page 62: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

S3 - have a structure• use folder structure • S3 not search friendly

Page 63: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

Firehose – mind the buffer• use the choice wisely

• buffer data size can

vary

• design the app/lambda

accordingly

Page 64: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

watch the DLQs

• prioritise failures

• selective & tiered monitoring

• implement re-play loop

• adjust DLQ delay time

Page 65: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

what next?

Page 66: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

➢ strengthen security

➢ lambda layers

➢ key/secrets rotation

➢ API caching

➢ unified CI/CD pipeline

➢ monitor ext services

➢ handling versions

➢ improve DLQ monitoring

➢ X-Ray

➢ staging env

➢ new projects

Page 67: serverless journey of shop.LEGO - Amazon Web Services€¦ · serverless journey of shop.LEGO.com ... • data driven Events PAB Site map Pricing Produ cts Stores Promo tions Custo

go

build

serverless

thank

you!

@sheenbrisals