40
@gamussa | @riferrei | #IMCSummit Keep your Data Close and your Caches Hotter using Apache Kafka, Connect and KSQL @gamussa | @riferrei | #IMCSummit

Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Keep your Data Close and your Caches Hotter using Apache Kafka, Connect and KSQL

@gamussa | @riferrei | #IMCSummit

Page 2: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

2

Page 3: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

Raffle, yeah 🚀

Page 4: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

Raffle, yeah 🚀Follow @gamussa @riferrei 📸 🖼 👬

Tag @gamussa @riferrei With #IMCSummit

Page 5: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

4

Data is only useful

if it is Fresh and

Contextual

Page 6: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Page 7: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

What if the airbag deploys 30 seconds after the collision?

Page 8: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Page 9: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

December 6th, 2010: Commuter rail train hits elderly

driver

Page 10: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

7

What if the information

about the commuter rail

train is outdated?

Page 11: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

8

Caches can be a Solution for Data

that is Fresh

Page 12: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

9

APIs need to access data freely and easily

CacheAPIRead

Write

Read

Write

Page 13: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

9

APIs need to access data freely and easily

● Data should never be treated as a scarce resource in applications

CacheAPIRead

Write

Read

Write

Page 14: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

9

APIs need to access data freely and easily

● Data should never be treated as a scarce resource in applications

● Latency should be kept as minimal to ensure a better user experience

CacheAPIRead

Write

Read

Write

Page 15: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

9

APIs need to access data freely and easily

● Data should never be treated as a scarce resource in applications

● Latency should be kept as minimal to ensure a better user experience

● Data should be not be static: keep the data fresh continuously

CacheAPIRead

Write

Read

Write

Page 16: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

9

APIs need to access data freely and easily

● Data should never be treated as a scarce resource in applications

● Latency should be kept as minimal to ensure a better user experience

● Data should be not be static: keep the data fresh continuously

● Find ways to handle large amounts of data without breaking the APIs

CacheAPIRead

Write

Read

Write

Page 17: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

10

Caches can be either built-in or distributed

CacheAPIRead

Write

Built-in Caches

Cache

API

Distributed Caches

Cache

Cache

Read

Write

Page 18: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

10

Caches can be either built-in or distributed● If data can fit into the API memory, then

you should use built-in caches

CacheAPIRead

Write

Built-in Caches

Cache

API

Distributed Caches

Cache

Cache

Read

Write

Page 19: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

10

Caches can be either built-in or distributed● If data can fit into the API memory, then

you should use built-in caches

● Otherwise, you may need to use distributed caches for large sizes

CacheAPIRead

Write

Built-in Caches

Cache

API

Distributed Caches

Cache

Cache

Read

Write

Page 20: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

10

Caches can be either built-in or distributed● If data can fit into the API memory, then

you should use built-in caches

● Otherwise, you may need to use distributed caches for large sizes

● Some cache implementations provides the best of both cases

CacheAPIRead

Write

Built-in Caches

Cache

API

Distributed Caches

Cache

Cache

Read

Write

Page 21: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

10

Caches can be either built-in or distributed● If data can fit into the API memory, then

you should use built-in caches

● Otherwise, you may need to use distributed caches for large sizes

● Some cache implementations provides the best of both cases

● For distributed caches, make sure to always find a good way to O(1)

CacheAPIRead

Write

Built-in Caches

Cache

API

Distributed Caches

Cache

Cache

Read

Write

Page 22: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

11

DEMO

Page 23: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

12

Page 24: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

12

Page 25: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

13

Join the fun!

Page 26: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

14

Page 27: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

15

Caching Patterns

Page 28: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Caching Pattern:Refresh Ahead

● Proactively updates the cache

● Keep the entries always in-sync

● Ideal for latency sensitive cases

● Ideal when data read is costly

● It may need initial data loading

Kafka Connect

Cache

Kafka Connect

API

Page 29: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Caching Pattern:Refresh Ahead / Adapt● Proactively updates the cache

● Keep the entries always in-sync

● Ideal for latency sensitive cases

● Ideal when data read is costly

● It may need initial data loading

Kafka Connect

Application Cache

Kafka Connect

Transform and adapt records before delivery

Schema Registry for canonical models

API

Page 30: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Caching Pattern:Write Behind● Removes I/O pressure from app

● Allows true horizontal scalability

● Ensures ordering and persistence

● Minimizes DB code complexity

● Totally handles DB unavailability

Kafka Connect

Application Cache

Kafka Connect

API

Page 31: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Caching Pattern:Write Behind / Adapt● Removes I/O pressure from app

● Allows true horizontal scalability

● Ensures ordering and persistence

● Minimizes DB code complexity

● Totally handles DB unavailability

Kafka Connect

Application Cache

Kafka Connect

Transform and adapt records before delivery

Schema Registry for canonical models

API

Page 32: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Caching Pattern:Event Federation● Replicates data across regions

● Keep multiple regions in-sync

● Great to improve RPO and RTO

● Handles lazy/slow networks well

● Works well if its used along with Read-Through and Write-Through patterns.

Confluent Replicator

<<MirrorMaker>>

Page 33: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

21

Kafka Connect Implementation

Strategies

Page 34: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Kafka Connect support for In-Memory Caches● Connector for Redis is open and it

is available in Confluent Hub

● Connector for Memcached is open and it is available in Confluent Hub

● Connectors for both GridGain and Apache Ignite implementations.

● Connector for InfiniSpan is open and is maintained by Red Hat

Kafka Connect

Kafka Connect

Kafka Connect

Kafka Connect

Page 35: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Frameworks for other In-Memory Caches● Oracle provides HotCache from

GoldenGate for Oracle Coherence

● Hazelcast has the Jet framework, which provides support for Kafka

● Pivotal GemFire (Apache Geode) has good support from Spring

● Good news: you can always write your own sink using Connect API

Oracle GoldenGate

Hazelcast Jet

Spring Data Spring Kafka

Connect Framework

Any Cache

Page 36: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Interested on DB CDC? Then meet Debezium!● Amazing CDC technology to pull

data out from databases to Kafka

● Works in a log level, which means true CDC implementation for your projects instead of record polling

● Open-source maintained by Red Hat. Have broad support for many popular databases.

● It is built on top of Kafka Connect

Page 37: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@gamussa | @riferrei | #IMCSummit

Support for Running Kafka Connect Servers● Run by yourself on BareMetal:

https://kafka.apache.org/downloads https://www.confluent.io/download

● IaaS on AWS or Google Cloud: https://github.com/confluentinc/ccloud-tools

● Running using Docker Containers: https://hub.docker.com/r/confluentinc/cp-kafka-connect/

● Running using Kubernetes: https://

github.com/confluentinc/cp-helm-chart https://www.confluent.io/confluent-operator/

Kafka Connect

Page 38: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

26

Stay in touch

cnfl.io/meetupscnfl.io/slack cnfl.io/blog

Page 39: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

@@gamussa | @riferrei | #IMCSummit

Thanks!@riferrei [email protected]

@gamussa [email protected]

https://slackpass.io/confluentcommunity #connect #ksql

Page 40: Keep your Data Close and your Caches Hotter - IMCS - 06-02 ... … · data fresh continuously API Cache Read Write Read Write. @gamussa | @riferrei | #IMCSummit 9 APIs need to access

28