picnic software - developing a flexible and scalable application

74
Developing a flexible and scalable application

Upload: nick-josevski

Post on 14-Jul-2015

70 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Picnic Software - Developing a flexible and scalable application

Developing a flexible and scalable application

Page 2: Picnic Software - Developing a flexible and scalable application
Page 3: Picnic Software - Developing a flexible and scalable application

Presenting Today

Andrew Browne Dave Churchill Basarat Syed

Nick Josevski Matt Walkenhorst

Page 4: Picnic Software - Developing a flexible and scalable application

Disclaimer

The views expressed here are solely those of the authors in their private capacity and do not in any way represent the views of the Picnic Software Pty Ltd, or any other associated entity or shareholder.

Picnic Software Pty Ltd has not approved, endorsed, embraced, friended, liked, tweeted, google-plused, pinterested, dugg, reddited, hacker-newsed, sanctioned or authorized this presentation.

Page 5: Picnic Software - Developing a flexible and scalable application
Page 6: Picnic Software - Developing a flexible and scalable application

Agenda

• App & Tech

• Infrastructure & Data Flow

• Deployment & Scalability

• Permissions with Neo4j

• Client Side Technologies

• Development & Testing Workflow

Page 7: Picnic Software - Developing a flexible and scalable application

What we do

• We are an ISV (Independent Software Vendor)

– Building and running a workflow/collaboration application

• Partnerships with large businesses in the Advertising/Marketing sector

• Our customers are primarily large retailers

Page 8: Picnic Software - Developing a flexible and scalable application

Our App

• Media Library

– High resolution files; PSDs, Video

• Collaborative workflows

– Coordinating inputs

• Photography, Illustrations, Graphic Design

– Producing advertising outputs

• Over multiple media channels – Catalogues, Billboards/Print, TV, Radio, Web

Page 9: Picnic Software - Developing a flexible and scalable application

Our Tech Stack

• F#, C#, ASP.NET MVC, ServiceStack

• EventStore, Eventful, RavenDB, Neo4j

• Angular, TypeScript, Mocha, Node, Sass

• SignalR, AutoMapper, RabbitMQ, LINQ, NSubstitute, Nunit, FSUnit, FParsec, FsCheck

• AWS, Docker, Riemann, Logstash, PowerShell, PSake, NodaTime

• GitHub, TeamCity, Octopus Deploy, Slack, YouTrack

Page 10: Picnic Software - Developing a flexible and scalable application

Flexibility

• Architecture choices to support

– Changes in requirements

– Future customers working in same domain

• When we started building we had

– Known customer workflows

– Known unknown customer workflows

– Unknown unknown customers workflows

Page 11: Picnic Software - Developing a flexible and scalable application

Questions

Page 12: Picnic Software - Developing a flexible and scalable application

Our Infrastructure

Andrew

Page 13: Picnic Software - Developing a flexible and scalable application

Sydney region

CloudFront

S3Core, Neo4j,

RavenDbRabbit,

EventStore

Media

Processing

Web

Elastic Load

Balancing

Availability Zone x 2

MySQL

HA Proxy

Page 14: Picnic Software - Developing a flexible and scalable application

S3

Page 15: Picnic Software - Developing a flexible and scalable application

CloudFront

Page 16: Picnic Software - Developing a flexible and scalable application

Elastic Load Balancer

Page 17: Picnic Software - Developing a flexible and scalable application

EC2

Page 18: Picnic Software - Developing a flexible and scalable application
Page 19: Picnic Software - Developing a flexible and scalable application
Page 20: Picnic Software - Developing a flexible and scalable application

Event Store

Page 21: Picnic Software - Developing a flexible and scalable application
Page 22: Picnic Software - Developing a flexible and scalable application
Page 23: Picnic Software - Developing a flexible and scalable application

Writes

Page 24: Picnic Software - Developing a flexible and scalable application

Reads

Page 25: Picnic Software - Developing a flexible and scalable application

S3

EventStore

Web

Availability Zone x 2

Core Neo4j RavenDb Media

Processing

Rabbit

Disposable

Page 26: Picnic Software - Developing a flexible and scalable application

Questions

Page 27: Picnic Software - Developing a flexible and scalable application

Deployment & Scalability

Matt

Page 28: Picnic Software - Developing a flexible and scalable application

Deployment

• Server Infrastructure – AWS

– Starting new instances largely a manual affair at this point

• Configuration Management – Chef

• Application deployment – Team City, Octopus Deploy

Page 29: Picnic Software - Developing a flexible and scalable application

Chef

“Give me six hours to chop down a tree and I will spend the first four sharpening the axe.”

Page 30: Picnic Software - Developing a flexible and scalable application

Chef

• Windows / Linux deployment nodes

• Each node is in an Environment

• Each node performs one or more Roles

• Each Role requires the running of one or more Recipes

• Recipes are stored in cookbooks

• Keep configuration in Git

• Keep CHEF Server configuration in Git

Page 31: Picnic Software - Developing a flexible and scalable application
Page 32: Picnic Software - Developing a flexible and scalable application

Octopus Deploy

• Windows code deployments only – Linux coming soon.

• Environments, Roles, Apps, Releases.• Deployment Process – steps executed on Roles to

“Tentacles”– Nuget packages retrieved from Team City– Store configuration as variables – Variable snapshot + Nuget packages = release– IIS, Windows Service, PowerShell steps available– Partial and Rolling deploys– Easy to roll back – just re-deploy last working release.

Page 33: Picnic Software - Developing a flexible and scalable application

SOON: Blue / Green Deployments

• Asgard brings up a NEW (GREEN) copy of production AWS infrastructure.

• Automatically Bootstrap instances against Chef and Octopus.

• Smoke test GREEN environment• Add GREEN web servers to load balancer• Remove OLD (BLUE) web servers from load

balancer• Asgard tears down BLUE production AWS

infrastructure.

Page 34: Picnic Software - Developing a flexible and scalable application

Message delivery between processes

• Requirements

– Reliable.

– Easy to manage.

– Easy to use.

– Low latency.

Page 35: Picnic Software - Developing a flexible and scalable application

Things we looked at (2+ years ago)

• NServiceBus

– Tied to MSMQ at the time.

• MassTransit

– Lacked documentation.

– Not ready for prime-time at that point.

• RabbitMQ + EasyNetQ

– Simple, best fit for us.

– Wrote our own client – bad idea.

Page 36: Picnic Software - Developing a flexible and scalable application
Page 37: Picnic Software - Developing a flexible and scalable application

RabbitMQ

• Written in Erlang, maintained by Pivotal.

• Linux / Windows.

• Easy administration (Web, command line, JSON).

• Supports– Clustering and failover.

– Durable and HA queues.

– ‘At least once’ delivery guaranteed.

– Direct, Fan-out and Topic exchanges.

– Partitioning (vhosts), Federation & Shovelling.

Page 38: Picnic Software - Developing a flexible and scalable application

How Picnic use RabbitMQ

• Setup

– Cluster of RabbitMQ servers behind ELB in multiple AZs.

• You can use HAProxy instead of ELB.

– EasyNetQ library by Mike Hadlow.

• Handles subscription, publish and reconnection logic.

– So solid now we hardly think about it.

Page 39: Picnic Software - Developing a flexible and scalable application

Use case: Scaling of long-running CPU and IO intensive operations

• File format conversion, Zip bundling, PDF & InDesign creation etc.

• Uses Topic exchange. Currently just one topic!

• Subscribers are round-robined by the broker.

• Subscribers are isolated – no clustering.

• Scaling - just launch new instances.

• Redundancy – launch in multiple Azs

• This has worked really well for us.

Page 40: Picnic Software - Developing a flexible and scalable application

Use case: Distribution to SignalRclients

• In-app notifications, long running task progress etc. to the browser.

• Each web server receives all messages (Fan-out exchange)

• Messages delivered to users / groups via SignalR

Page 41: Picnic Software - Developing a flexible and scalable application

Questions

Page 42: Picnic Software - Developing a flexible and scalable application

Scalable Permissions

Dave

Page 43: Picnic Software - Developing a flexible and scalable application

Permissions Model

<approval-1-guid> Owner

<footwear-folder-guid> Write

• All entities in the system are identified by GUIDs• Each permission applies to a specific entity

Page 44: Picnic Software - Developing a flexible and scalable application

Permissions Model

<approval-1-guid> Owner

<footwear-folder-guid> Write

• Permissions also have a role

<footwear-folder-guid> Read

Page 45: Picnic Software - Developing a flexible and scalable application

Permissions Model

<approval-1-guid> Owner

<footwear-folder-guid> Write

• Each user has a corresponding "Me" permission

<footwear-folder-guid> Read

<user-dave-guid> Me

Page 46: Picnic Software - Developing a flexible and scalable application

Permissions Model

<approval-1-guid> Owner

<footwear-folder-guid> Write

• As events arrive, relationships are built up between permissions• e.g. a JobCreated event might give Owner permission to the creator

<footwear-folder-guid> Read

<user-dave-guid> Me

Page 47: Picnic Software - Developing a flexible and scalable application

Permissions Model

<approval-1-guid> Owner

<footwear-folder-guid> Write

• Relationships don't have to stem from the Me permissions• e.g. having Write permission on a folder could mean you can also Read

<footwear-folder-guid> Read

<user-dave-guid> Me

Page 48: Picnic Software - Developing a flexible and scalable application

Permissions Model

<approval-1-guid> Owner

<footwear-folder-guid> Write

• A user has a permission if there's a path from the user's Me node• This user doesn't have Read on the folder

<footwear-folder-guid> Read

<user-dave-guid> Me

Page 49: Picnic Software - Developing a flexible and scalable application

Permissions Model

<approval-1-guid> Owner

<footwear-folder-guid> Write

• A user has a permission if there's a path from the user's Me node• Giving Write on the footwear folder also gives the user Read

<footwear-folder-guid> Read

<user-dave-guid> Me

Page 50: Picnic Software - Developing a flexible and scalable application

Original Implementation

Write

Read

Me

ApprovalOwner

• RavenDB document for each permission• Records which permissions directly inherit this permission

Read <footwear-folder-guid>:

[Write <footwear-folder-guid>]

Write <footwear-folder-guid>:

[Me <user-dave-guid>]

Owner <approval-1-guid>:

[Me <user-dave-guid>]

Me <user-dave-guid>:

[]

Page 51: Picnic Software - Developing a flexible and scalable application

Original Implementation

Write

Read

Me

ApprovalOwner

• Worker task builds a second state document for each permission

• Records all permissions which inherit this permission

Read <footwear-folder-guid>:

[Write <footwear-folder-guid>,

Me <user-dave-guid>]

Write <footwear-folder-guid>:

[Me <user-dave-guid>]

Owner <approval-1-guid>:

[Me <user-dave-guid>]

Me <user-dave-guid>:

[]

Page 52: Picnic Software - Developing a flexible and scalable application

Original Implementation

Write

Read

Me

ApprovalOwner

• A user has a permission if their Me appears in the permission's state document

Read <footwear-folder-guid>:

[Write <footwear-folder-guid>,

Me <user-dave-guid>]

Page 53: Picnic Software - Developing a flexible and scalable application

Original Implementation - Issues

• State documents can get large• Introduce intermediate groups

• Takes time for state documents to be updated• Cache and update permission graph in process

• Other processes can still sometimes see out-of-date permissions• Use a graph database!

Page 54: Picnic Software - Developing a flexible and scalable application
Page 55: Picnic Software - Developing a flexible and scalable application

New Implementation

• In process of switching to Neo4j

• Transactional updates• No need to calculate intermediate state• Faster• Simpler

• Still need to send some state data across to RavenDB for permissions when searching

Page 56: Picnic Software - Developing a flexible and scalable application
Page 57: Picnic Software - Developing a flexible and scalable application

Questions

Page 58: Picnic Software - Developing a flexible and scalable application

Client Side Architecture

Bas

Page 59: Picnic Software - Developing a flexible and scalable application

http://slides.com/basarat/picnic-frontend

Page 60: Picnic Software - Developing a flexible and scalable application

Questions

Page 61: Picnic Software - Developing a flexible and scalable application

Development Workflow

Nick

Page 62: Picnic Software - Developing a flexible and scalable application

Development Workflow

• GitHub

– Feature branches

– Pull Requests

Page 63: Picnic Software - Developing a flexible and scalable application

Pull Requests

• Just over 2 months now using the PR based workflow

• Approx 120 closed pull requests so far

• How

– Features branches, GitHub Tagging, TeamCity build process comments against PR

– Asynchronous task for a team member

• “Here’s a PR please review when you can”

Page 64: Picnic Software - Developing a flexible and scalable application

Team City & Tagging

Page 65: Picnic Software - Developing a flexible and scalable application

Development Workflow

• Why

– It was recommended to us.

– Supports consistent and frequent code reviews.

• Improves code quality

• Shares knowledge amongst the team

– Lets us catch some bugs much earlier.

Page 66: Picnic Software - Developing a flexible and scalable application
Page 67: Picnic Software - Developing a flexible and scalable application

Development Workflow

• The wins

– Build server is more often in a green state.

• Can push to your PR branch to rely on CI to give feedback

– Knowledge sharing

• “Oh, that’s how you solved that”

• Reducing silo effects

– Offer constructive feedback to others

• “This could be made better by…”

– Bugs / issues caught

• Typos, debug code left in, incomplete/missed features

Page 68: Picnic Software - Developing a flexible and scalable application

Development Workflow

• Testing

– Each PR builds as if it was already merged

– Unit/Integration tests run against PR in TeamCity

– YouTrack bugs marked with build numbers to track deployment

Page 69: Picnic Software - Developing a flexible and scalable application

Development Workflow

Page 70: Picnic Software - Developing a flexible and scalable application

Development Workflow

• Agility

– Tracking feature changes as they evolve alongside code

• As with all documentation - trying our best to keep up to date

• PRs feedback can “code change not reflected in docs”

– Testing team

• Can review these changes and be more up to date with

• Review PRs for an idea of scope of changes and where to look for issues

Page 71: Picnic Software - Developing a flexible and scalable application

Development Workflow

Page 72: Picnic Software - Developing a flexible and scalable application

Questions

Page 73: Picnic Software - Developing a flexible and scalable application

Thanks

Page 74: Picnic Software - Developing a flexible and scalable application

Other ALT.NET Presentations by us

Event Sourcing with F# - Andrew BrowneThinking in a document centric

world with RavenDB - Nick Josevski