Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Multi-Datacenter Kafka at Blibli.com

Multi-Datacenter Kafka at Blibli.com

Multi-Datacenter Kafka at Blibli.com

Eko Kurniawan Khannedy

November 15, 2018
Tweet

More Decks by Eko Kurniawan Khannedy

Other Decks in Technology

Transcript

  1. MULTI-DATACENTER KAFKA EKO KURNIAWAN KHANNEDY ▸ Senior Principal R&D Engineer

    at Blibli.com ▸ JVM User Group Indonesia Committee ▸ Blogger & Vlogger
  2. MULTI-DATACENTER KAFKA MESSAGE BROKER IN BLIBLI.COM ▸ Use RABBITMQ from

    the beginning ▸ Start using KAFKA in 2015 ▸ Deprecated RABBITMQ in 2017 because scalability issue ▸ Migrating from RABBITMQ to KAFKA until now
  3. MULTI-DATACENTER KAFKA MESSAGE BROKER IN BLIPAY ▸ Start develop Blipay

    system in 2017 ▸ Using Event-Driven Architecture (No HTTP Call beetwen services, All communication using Message Broker) ▸ KAFKA is the only Message Broker in Blipay ▸ Based on regulation in Indonesia, Blipay must using multi data-center for disaster recovery
  4. MULTI-DATACENTER KAFKA BLIPAY ARCHITECTURE BLIPAY-API BLIPAY-MEMBER BLIPAY- MERCHANT BLIPAY- TRANSACTION

    BLIPAY-PAYMENT BLIPAY- NOTIFICATION BLIPAY- PROMOTION APACHE KAFKA MONGODB MONGODB POSTGRE MONGODB MONGODB REDIS POSTGRE
  5. MULTI-DATACENTER KAFKA ALL COMMUNICATION USING KAFKA BLIPAY-API BLIPAY-MEMBER BLIPAY- MERCHANT

    BLIPAY- TRANSACTION BLIPAY-PAYMENT BLIPAY- NOTIFICATION BLIPAY- PROMOTION APACHE KAFKA 1. HTTP Request 2. HTTP Request 4. SaveBalanceEvent 3. Some Events 4. SaveTransactionEvent
  6. MULTI-DATACENTER KAFKA SOLUTION NO 1 MICROSERVICES APACHE KAFKA CLUSTER MICROSERVICES

    APACHE KAFKA CLUSTER MIRROR MAKER MIRROR MAKER DATABASES DATABASES
  7. MULTI-DATACENTER KAFKA PROBLEM WITH SOLUTION NO 1 ▸ INFINITE LOOP

    ▸ Mirror Maker in datacenter 1 send message to datacenter 2 ▸ Mirror Maker in datacenter 2 receive the message, and send back to datacenter 1
  8. MULTI-DATACENTER KAFKA PROBLEM WITH SOLUTION NO 2 ▸ All services

    in all datacenter will consume the message. ▸ For blipay-notification, we receive duplicate sms & email
  9. MULTI-DATACENTER KAFKA SOLUTION NO 3 MICROSERVICES APACHE KAFKA CLUSTER MICROSERVICES

    APACHE KAFKA CLUSTER DATABASES DATABASES Database Mirroring
  10. MULTI-DATACENTER KAFKA PROBLEM WITH SOLUTION NO 3 ▸ Not all

    services using database ▸ Some services need to react based on event, like blipay-notification.
  11. MULTI-DATACENTER KAFKA SOLUTION NO 4 MICROSERVICES APACHE KAFKA CLUSTER MICROSERVICES

    APACHE KAFKA CLUSTER DATABASES DATABASES Database Mirroring MIRROR MAKER
  12. MULTI-DATACENTER KAFKA PROBLEM WITH SOLUTION NO 4 ▸ All services

    in all datacenter will consume the message. ▸ And we still get duplicate sms & email ▸ And now we get error DUPLICATE PRIMARY KEY, because database sync and service receive message from kafka
  13. MULTI-DATACENTER KAFKA SOLUTION NO 5 MICROSERVICES APACHE KAFKA CLUSTER MICROSERVICES

    APACHE KAFKA CLUSTER DATABASES DATABASES Database Mirroring MIRROR MAKER Block 
 Network
  14. MULTI-DATACENTER KAFKA RESULT WITH SOLUTION NO 5 ▸ No duplicate

    primary key ▸ No duplicate sms & email ▸ And we are happy :D
  15. MULTI-DATACENTER KAFKA DISASTER RECOVERY SIMULATION ▸ Shutdown datacenter 1 ▸

    Switch all traffic to datacenter 2 ▸ Unblock microservices network to kafka
  16. MULTI-DATACENTER KAFKA AND THE RESULT ARE ... ▸ All microservice

    start consuming all kafka message from beginning ▸ Duplicate Primary Key Error EVERYWHERE! ▸ We receive SMS & Email again from beginning
  17. MULTI-DATACENTER KAFKA SOLUTION NO 6 MICROSERVICES APACHE KAFKA CLUSTER MICROSERVICES

    APACHE KAFKA CLUSTER DATABASES DATABASES Database Mirroring MIRROR MAKER Block 
 Network OFFSET
 SYNC
  18. MULTI-DATACENTER KAFKA AND THE RESULT ARE ... ▸ No duplicate

    primary key ▸ No duplicate sms & email ▸ And we are happy :D
  19. MULTI-DATACENTER KAFKA AND THIS IS WHAT HAPPENS WHEN WE DEPLOY

    NEW FEATURES ▸ We start receiving sms & email about blipay from beginning, 
 but not all sms & email. ▸ Some service start reconsuming kafka messages from begining, 
 but again, not all messages. ▸ Now we are getting confused
  20. SO IF IN 1 DAY, THERE IS NO ACTIVITY IN

    THE OFFSET, IT WILL RESET TO ZERO