making session stores more intelligent - qcon san francisco · 2020-05-14 · couchbase cassandra...

Post on 20-May-2020

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Making Session Stores More IntelligentKYLE J. DAVIS

TECHNICAL MARKETING MANAGER

REDIS LABS

Whatisasessionstore?

• Anchunkofdatathatisconnectedtoone“user”ofaservice– ”user”canbeasimplevisitor– orproperuserwithanaccount

• Oftenpersistedbetweenclientandserverbyatokeninacookie*– Cookieisgivenbyserver,storedbybrowser– Clientsendsthatcookiebacktotheserveronsubsequentrequests– Serverassociatesthattokenwithdata

• Oftenthemostfrequentlyuseddatabythatuser– Datathatisspecifictotheuser– Datathatisrequiredforrenderingorcommonuse

• Oftenephemeralandduplicated

Asessionstoreis…

Session Storage Uses Cases

Traditional• Username• Preferences• Name• “Stateful” data

Intelligent• Traditional +• Notifications• Past behaviour– content surfacing– analytical information– personalization

In a simple world

Internet Server Database

Good problems

Internet Server DatabaseTraffic Grows… Struggles

Good solution

Internet Server Database

performance restored

Session storage on the server

More good problems

Internet Server DatabaseSession storage

on the server

Struggling

Problematic Solutions

Internet Server DatabaseSession storage

on the server

Load balanced

Session storage on the server

Multiple Servers + On-server Sessions?

Server DatabaseRobin

Server#1– HelloRobin!

Multiple Servers + On-server Sessions?

Server DatabaseRobin

Server#3– Hello????

Better solution

Internet Server Database

Load balanced

RedisSession Storage

WhatisRedis?

WhoWeAre

Opensource.Theleadingin-memorydatabaseplatform,supportinganyhighperformanceoperational,analyticsorhybridusecase.

TheopensourcehomeandcommercialproviderofRedisEnterprisetechnology,platform,products&services.

14

RedisTopDifferentiators

Simplicity ExtensibilityPerformanceNoSQLBenchmark

1

Redis DataStructures

2 3

Redis Modules

15

Lists

Hashes

Bitmaps

Strings

Bitfield

Streams

Hyperloglog

SortedSets

Sets

GeospatialIndexes

Performance:TheMostPowerfulDatabase

HighestThroughputatLowestLatencyinHighVolumeofWritesScenario

LeastServersNeededtoDeliver1MillionWrites/Sec

BenchmarksperformedbyAvalonConsultingGroup BenchmarkspublishedintheGoogleblog

16

1

Serversu

sedtoachieve1Mwrites/sec

10k

20k

30k

40k

0

100

200

300

400

500

0Couchbase Cassandra Datastax Redise

394.42 381.31 372.31

71.22App

licat

ion

requ

ests

/sec

Latency in Milliseconds

Applica!on Latency (msec)

CouchbaseCassandra Redise

$14,832$371,040$2,226,216

25X150X

ANNUAL COST

COST COMPAREDTO REDISe

350

300

250

200

150

100

50

0

Simplicity: DataStructures- Redis’BuildingBlocks

Lists[A→B→C→D→E]

Hashes{A:“foo”,B:“bar”,C:“baz”}

Bitmaps0011010101100111001010

Strings"I'maPlainTextString!”

Bitfield{23334}{112345569}{766538}

Key

17

2

”Retrievethee-mailaddressoftheuserwiththehighestbidinanauctionthatstartedonJuly24that11:00pmPST” ZREVRANGE07242015_230000=

Streamsà{id1=time1.seq1(A:“xyz”,B:“cdf”),

d2=time2.seq2(D:“abc”,)}à

Hyperloglog0011010111001110

SortedSets{A:0.1,B:0.3,C:100 }

Sets{A,B,C,D,E}

GeospatialIndexes{A:(51.5,0.12),B:(32.1,34.7)}

• Add-onsthatuseaRedisAPItoseamlesslysupportadditionalusecasesanddatastructures.

• EnjoyRedis’simplicity,superhighperformance,infinitescalabilityandhighavailability.

Extensibility: ModulesExtendRedisInfinitely

• AnyC/C++/GoprogramcanbecomeaModuleandrunonRedis.

• Leverageexistingdatastructuresorintroducenewones.

• Canbeusedbyanyone;RedisEnterpriseModulesaretestedandcertifiedbyRedisLabs.

• TurnRedisintoaMulti-Model database

18

3

Redise PackManagedFullymanagedRedise

Packinprivatedatacenters

Redise PackDownloadableRedisesoftwareforany

enterprisedatacenterorcloudenvironment

Redise CloudPrivateFullymanaged,server-lessscalingRedise

serviceinVPCswithinAWS,MSAzure,GCPandIBMSoftlayer

Redise CloudFullymanaged,server-lessRedise serviceonhostedresources

withinAWS,MSAzure,GCP,IBMSoftlayer,Heroku,CFand

OpenShift

RedisLabsProducts

19

or or or

DBaaS Software

Concepts

• Probabilisticdatastructure• Hash->samplebits->setbits• Properties:– Falsenegatives– notpossible– Falsepositives– possible,butcontrollable– Bitsperitemstored– Addorcheckifexists– LiketheTardis,it’sbiggerontheinsidethanoutside

• Availability:– Redis Module– Ontopofbitfields

Concept:BloomFilters(presence)

• Probabilisticdatastructure• Hash->countruns->storeruns• Properties:– Estimatesuniqueitems– Bitsperitemstored– 264uniqueitemsin12kb/errorrate0.81%– Add,countormerge!– LiketheTardis,it’sbiggerontheinsidethanoutside

• Availability:– AllversionsofRedis

Concept:HyperLogLog (cardinality)

engineering.conversantmedia.com

• It’sjustbits!• Fixedstartingpoint,eachpointrepresentsamomentintime,fliptorepresentactivity• Properties:– Sizerelativetolengthoftime(byteround)– Counttotalsorranges– BITOP(AND/XOR/OR/NOT)

• Availability:– AllversionsofRedis

Concept:Bitcounting(timeseries)

GroupNotifications

Process

• Groupofusersgetnotification“Saleonsweaters”• Insertintocentraltableofnotifications• Insertrowintablewitheachuserofgroupwithnotificationandseenflag• Eachtimeitisneeded,querynotificationstablewhereseenflagisfalse.

TraditionalGroupNotificationPattern

TraditionalGroupNotificationPatternChallenges

• Adding/removingmeanstouchingarowforeachuseringroup.– Fineforgroupsof10users,whatabout1million?– Alsomulti-step

• Storageisproportionaltosizeofgroupandnotifications• ConstantDBhits,noteasilycacheable• Setting“read”isDBwrite

Process

• Addnotificationtosinglegroupbasedstructureortable(easilycacheable)• Firstn notificationsarereadbyallusersingroup.• Thenotificationsarecheckedtoseeiftheyareinasession-basedBloomfilterornot.• MarkreadbyaddingtoBloomfilterinsessionstore.

Modern&IntelligentGroupNotificationPattern

Modern&IntelligentGroupNotificationPatternAdvantages

• Addinganotificationonlywritestoasingletable,singlerow.• Modelfitsuse– unreadassumed.• Fast.Checkingforread/writingreadisunrelatedtonumberofitemsinthefilter.Consistent.• ~5-bits peritem,butBloomfilterdoesn’talwaysgrow.• Gentlescaling

Visual

Notification#1Notification#2Notification#3Notification#4Notification#5Notification#6

✗✔

✗✔

Notification#1Notification#2Notification#3Notification#4Notification#5Notification#6

FreshContent

Process

• Handpickandrotateasmallnumberofcontent/items• StoredinDBtable• Servedoutdumblytousers

TraditionalContentSurfacingPattern(Basic)Challenges

• Mayservecontentmultipletimes• Freshnessislinkedtoamanualcuratorialprocess

TraditionalContentSurfacingPattern(Advanced)

Process

• Batchprocessbuildscontentlisttosurfaceforeachuser• ListisstoredinDBTable• Servedouttouser• Rotatedonaschedule

Challenges

• NotReal-time• Mayservecontentmultipletimes• Un-cacheableDBcontent• Hardtoscale

Process

• MiddlewareaddseachcontentreadtoaBloomfilterstoredinthesession• Featuredcontentlistisbuilt,canbeextensive.• FeatureditemsarecheckedvsBloomfilteron-the-fly

Modern&IntelligentContentSurfacingPatternAdvantages

• NoDBhitsforuser• Featuredcontentiscacheable• Willnottoshowcontentmultipletimesifread• Tinystoragerequirementsevenatscale• Freshnesscanbeachievedwithzero/lowhumaninput• Real-timerecordingofactivity–immediateimpactonfreshcontent

Visual

Content#1Content#2Content#3Content#4Content#5Content#6

✗✔

✗✔

Content#1

Content#1

Content#3

Content#5

ActivityPatternMonitoring&Personalization

• Monitortheusagebehaviour– Contentviewed– Activityovertime– Combinationsofcontenthistoryandactivity

• Personalizethecontentbasedonthebehaviour• Seenasdifficulttoaccomplish– Analyticsdata

• Storedinanotherservice• Anonymized

– ComplicatedgraphorMLbasedsolutions• Inferences• Blackboxes

ActivityPatternMonitoring&Personalization?

• Recordsiteactivitywithbitcounting• UniquepageviewsinHyperLogLog• LeveragethepagevisitBloomfilter• Simplercounterforpagesconsumed• Createcriteriabasedonsessionstoredanalytics– Newtoapage?Bloomfilter– Newtothesite?UniquePageview=1(HLL)&&PreviouslyVisited=false(Bloom)– Inactiveuser?Sumthebitcountoverthelastfiverecords,if=0theninactive– Beentoaclusterofpages(inferinterest)?CheckclusterofpagesvsBloomfilter– combo!

ActivityPatternMonitoring&Personalization

• Whyisthissuddenlypossible?– Probabilisticdatastructuresaresmall/fast– Bitcountingissmall/fast– Decoupledfromoperationaldatabase

• Whataboutprivacy?– Legitimateconcern– Non-reversibleprobabilisticstructures– Siloed fromrestofdatabase

ActivityPatternMonitoring&Personalization

Questions?

Thankyou!Demosourcecode:https://github.com/stockholmux/qcon-redis-session-store-demo

top related