atmosphere conference 2015: pubsub++ - few tips that make your life with kafka easier

46
Krzysztof Dębski Atmosphere 2015 PubSub++ or how to make life with Kafka easier

Upload: proidea

Post on 25-Jul-2015

26 views

Category:

Internet


0 download

TRANSCRIPT

Page 1: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

Krzysztof DębskiAtmosphere 2015

PubSub++or how to make life with Kafka easier

Page 2: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Why do we need a PubSub?

Page 3: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Service

Service

Service

Service

Service

Service

Service

Service

Service

Service

Service

Distributed environment

Page 4: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Service

Service

Service

Service

Service

Service

Service

Service

Service

Service

Service

Domain

Domain

Domain

Distributed environment

Page 5: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Orchestration vs. Choreography

Page 6: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Kafka

Page 7: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Kafka architecture

Service

Producer

Service

Consumer

KafkaBroker

Zookeeper< Kafka 0.9

Page 8: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Kafka data1

0 9 78 6 5 34 2 1

8 5 4 2 1

10 9 7 6 3

5 4 2

8 1

Data Topic Partition

Page 9: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Consumer groups

Consumer 1

Broker

P0

Broker

P1

Broker

P2

Broker

P3

Consumer 2

Consumer 3

Consumer 4

Consumer 5

Consumer 6

Consumer group 1 Consumer group 2

Page 10: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Publish & subscribe

Producer_1…Producer_n

Consumer_group_1Consumer_group_2

Remove old messages

Remove old events

Publish event

Read eventRead event

Page 11: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Leader & Replicas

Service

Producer

Service

Consumer

Broker

Zookeeper

Broker

Broker

P1 P0

P2 P1

P0 P2

Page 12: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Rebalancing leadersBroker 1

Broker 2

Broker 3

P1 P0

P2 P1

P0 P2

Topic: test Partition count: 3 Replication factor: 1Configs: retention.ms=86400000

Topic: test Partition: 0 Leader: 3Replicas: 3, 1 ISR: 3, 1Topic: test Partition: 1 Leader: 1Replicas: 1, 2 ISR: 1, 2Topic: test Partition: 2 Leader: 2Replicas: 2, 3 ISR: 2, 3

Page 13: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Rebalancing leadersBroker 1

Broker 2

Broker 3

P1 P0

P2 P1

P0 P2

Topic: test Partition count: 3 Replication factor: 1Configs: retention.ms=86400000

Topic: test Partition: 0 Leader: 3Replicas: 3, 1 ISR: 3, 1Topic: test Partition: 1 Leader: 1Replicas: 1, 2 ISR: 1, 2Topic: test Partition: 2 Leader: 2Replicas: 2, 3 ISR: 2, 3

Page 14: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Rebalancing leadersBroker 1

Broker 2

Broker 3

P1 P0

P2 P1

P0 P2

Topic: test Partition count: 3 Replication factor: 1Configs: retention.ms=86400000

Topic: test Partition: 0 Leader: 1Replicas: 3, 1 ISR: 1Topic: test Partition: 1 Leader: 1Replicas: 1, 2 ISR: 1, 2Topic: test Partition: 2 Leader: 2Replicas: 2, 3 ISR: 2

Page 15: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Rebalancing leadersBroker 1

Broker 2

Broker 3

P1 P0

P2 P1

P0 P2

Topic: test Partition count: 3 Replication factor: 1Configs: retention.ms=86400000

Topic: test Partition: 0 Leader: 1Replicas: 3, 1 ISR: 1, 3Topic: test Partition: 1 Leader: 1Replicas: 1, 2 ISR: 1, 2Topic: test Partition: 2 Leader: 2Replicas: 2, 3 ISR: 2, 3

Page 16: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Acknowledges

0 - don’t wait for response from broker

1 - only leader needs to respond

-1 - all replicas in sync

Spee

d

Safety

Page 17: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Events security

Basically, there is no authentication

You can create any topic

You can publish everywhere

You can subscribe to any topic

Page 18: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Page 19: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Synchronous world

RESTService

AService

B

Page 20: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Asynchronous made simple

Service A

Service B

REST REST/JMS

Page 21: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Hermes

Hermes Frontend

Hermes Frontend

Hermes Frontend

Hermes Consumer

Hermes Consumer

REST

REST, JMS

Page 22: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Event identification

Hermes Frontend

KafkaBroker

POST{“event”: ”test”}

{ "id": "58d7ff07-dd0e-4103-9b1f-55706f3049e6", "timestamp”: 1430443071995, “data”: {“event”: ”test”}}

HTTP 201 CreatedMessage-id: 58d7ff07-dd0e-4103-9b1f-55706f3049e6

Page 23: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

100 ms timeout(on the client side)

Page 24: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Network

Nagle’s algorithm 42 ms -> 6 ms

High load on client serverswrong timeout calculation

Page 25: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

65 ms timeout(on the server side)

Page 26: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Normal operation

Hermes Frontend

Producer

Hermes Consume

rConsumer

KafkaBroker

Zookeeper

POST

HTTP201Created

Page 27: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Slow kafka response

Hermes Frontend

Producer

Hermes Consume

rConsumer

KafkaBroker

Zookeeper

POST

HTTP202Accepted

Page 28: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Improved offset management

HermesProducer

Hermes consumer

Remove old messages

Publish event

Commited

Local unsent queue

Read event

Page 29: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Resend messages

Hermes consumer

Remove old messages

Local unsent queue

New event

Serviceinstanc

e

Page 30: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Resend messages

Hermes consumer

Remove old messages

Local unsent queue

New event

Serviceinstanc

e

HTTP 503 Unavailable

Page 31: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Resend messages

Remove old messages

Local unsent queue

New event

Serviceinstanc

e

HTTP 503 Unavailable

Check TTL & Add to queue

Hermes consumer

Page 32: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Resend speed

100% adapt 1/s 1/min

Page 33: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Lost events

Hermes Frontend

Producer

Hermes Consume

rConsumer

KafkaBroker

Zookeeper

Tracker

Publicationdata Deliv

ery

attempts

Page 34: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Groups and Topics

pl.allegro.hermes.demo.basic Group Topic

Page 35: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Security

Authentication and authorization interfaces

You can create any topic in your group

You can publish everywhere

Group owner defines subscriptions

Page 36: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Multi datacenter

Hermes Frontend

Hermes Manager

Hermes Frontend

Hermes Consumer

Hermes Consumer D

C 2D

C 1

Page 37: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

What’s in it for me?

Page 38: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

What we plan to do?

Page 39: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Lower overhead

Avro

RFC 7540

Page 40: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Avro

RFC 7540 => HTTP/2

Lower overhead

Page 41: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Improve security

Service authentication

Page 42: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

What’ve we learned?

Page 43: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Tradeoffs

You cannot have exactly one delivery

http://bravenewgeek.com/you-cannot-have-exactly-once-delivery/

Page 44: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Clients

Not all clients are the same.

Page 45: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@DebskiChris Kraków, 19.05.2015, Atmosphere

Early adopters are your friends

You know exactly what features are needed.

Page 46: Atmosphere Conference 2015: PubSub++ - few tips that make your life with kafka easier

@debskichris

allegrotech.io