+ All Categories
Home > Technology > QCon SP 2016 - Video Authorization: from chaos to 25ms response time

QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Date post: 12-Apr-2017
Category:
Upload: emerson-macedo
View: 1,124 times
Download: 0 times
Share this document with a friend
109
Video Authorization From chaos to 25ms response time
Transcript
Page 1: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Video AuthorizationFrom chaos to

25ms response time

Page 2: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Emerson Macedo@emerleite

https://emerleite.com

Page 3: QCon SP 2016 - Video Authorization: from chaos to 25ms response time
Page 4: QCon SP 2016 - Video Authorization: from chaos to 25ms response time
Page 5: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content authorizationis always

a challenge

Page 6: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Video Authorization process

Page 7: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Video Authorization process

Page 8: QCon SP 2016 - Video Authorization: from chaos to 25ms response time
Page 9: QCon SP 2016 - Video Authorization: from chaos to 25ms response time
Page 10: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Video authorizationmust be really

very fast

Page 11: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Authorization Provider

Rules

Page 12: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

1 - User has a valid session

Page 13: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

2 - User has the channel of this video in his Pay TV

subscription

Page 14: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

3 - User parental control matches video content

rating

Page 15: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

OR ...

Page 16: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

1 - User has a valid session

Page 17: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

2 - Video channel has a trial happening

Page 18: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

3 - User is able to join the current trial

Page 19: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Video Authorization process

Page 20: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

response time > 5 secondsCircuit Breaker opens

Page 21: QCon SP 2016 - Video Authorization: from chaos to 25ms response time
Page 22: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Nobody can playany subscriber only

video

Page 23: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

We need todo something

about this

Page 24: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

1 - split the circuit breaker

Page 25: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

The circuit breaker was like this

Page 26: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

The new circuit breaker is per provider

Page 27: QCon SP 2016 - Video Authorization: from chaos to 25ms response time
Page 28: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

A circuit open for one provider

should not affect any other providers

Page 29: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

2 - Optimize Auth Provider

Page 30: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Globosat PlayAuthorization Provider

Page 31: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Usually~ 500ms response time

Page 32: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Sometimes5s to 10s response time

Page 33: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Video authorizationmust be really

very fast

Page 34: QCon SP 2016 - Video Authorization: from chaos to 25ms response time
Page 35: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

New Relic Transaction Trace

Page 36: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

New Relic Transaction Trace

Page 37: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

2.1 - Snapshot someexternal services data

Page 38: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Globosat PlayAuthorization Provider

Page 39: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

After every user sign in

Page 40: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Before User InfoSnapshot data

Page 41: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

After User InfoSnapshot data

Page 42: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

On user video authorization

Page 43: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Before Profile ConfigSnapshot data

Page 44: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

After Profile ConfigSnapshot data

Page 45: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

On any video authorization

Page 46: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Before Video infoSnapshot data

Page 47: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

After Vide InfoSnapshot data

Page 48: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

In the worst scenarioWe have THREE external calls

Page 49: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

In the best scenarioWe have NO external calls

Page 50: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

2.2 - Be safe with allexternal services calls

Page 51: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 52: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 53: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 54: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 55: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 56: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 57: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 58: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 59: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 60: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 61: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 62: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 63: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 64: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 65: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 66: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 67: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 68: QCon SP 2016 - Video Authorization: from chaos to 25ms response time
Page 69: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Content Gateway 1

1 https://goo.gl/fg5Nzf

Page 70: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

2.3 - Cache logged requests

when it's safe

Page 71: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Logged request - Success

Page 72: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Logged request - Failure

Page 73: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Nginx Cache Config

Page 74: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

With Nginx cache

Page 75: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

We dida very intesive job

and reduced theresponse time

Page 76: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Usually~25ms response time

Page 77: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Usually~25ms response time

Page 78: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

BUT ...

Page 79: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Sometimes5s to 10s response time

Page 80: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Sometimes5s to 10s response time

Page 81: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

3 - Take a look at ourinfrastructure

Page 82: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

3.1 - MongoDB

Page 83: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

MongoDB has a bad reputation in software developer community

Page 84: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Everybody Blames Mongo everytime 2

2 http://rhaas.blogspot.com.br/2014/04/why-clock-is-ticking-for-mongodb.html

Page 85: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Everybody Blames Mongo everytime 3

3 http://cryto.net/~joepie91/blog/2015/07/19/why-you-should-never-ever-ever-use-mongodb/

Page 86: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Database change isan architectural decision

Page 87: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

architectural decisionsare hard and very

expensive to change

Page 88: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Sometimes5s to 10s response time

Page 89: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Strange query convultions

Page 90: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Traces confirms convultions

Page 91: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Logs confirms convultions

Page 92: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

We checked all indexesand found nothinghurting our system

Page 93: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

3.2 - Servers

Page 94: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

CPU Wait confirms convultions

Page 95: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Load average confirms convultions

Page 96: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

MongoDB docs confirms thatSomething was wrong 4

4 https://docs.mongodb.org/manual/administration/production-notes/#remote-filesystems

Page 97: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

MongoDB users group confirms thatSomething was wrong 5

5 https://groups.google.com/forum/#!msg/mongodb-user/Kd85b2HHVn8/7SnwTyeQKsEJ

Page 98: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

We removed NFSfrom our Mongodb

servers setup

Page 99: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

convultions stopped

Page 100: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Usually~25ms response time

Page 101: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Usually~25ms response time

Page 102: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

AND ...

Page 103: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Sometimes100ms to 500ms response time

Page 104: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Lessons Learned

Page 105: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

1 - Go deep into your problem

Page 106: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

2 - Don't panic

Page 107: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

3 - Most of the timethe solution is not

to rewrite from scratch

Page 108: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Questions?

Page 109: QCon SP 2016 - Video Authorization: from chaos to 25ms response time

Recommended