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

Данил Арендарский — Реализация паттерна Outbox ...

Ozon Tech
March 28, 2023

Данил Арендарский — Реализация паттерна Outbox для Apache Kafka

Ozon Tech

March 28, 2023
Tweet

More Decks by Ozon Tech

Other Decks in Technology

Transcript

  1. 2

  2. 3

  3. 6

  4. Pod 1 Pod 3 Pod 2 Пачка данных 1 Пачка

    данных 2 Пачка данных 3 ? 7 Partition 0 Partition 1 Partition 2 Kafka Pod leader Produce
  5. 8

  6. 9

  7. 13

  8. Топик выдач на завершение inbox_message ( , topic, key, payload)

    outbox_request (id, , type , status, attempt, next_attempt_date) * : Создать документы Создать перевозку … 15
  9. 16

  10. 17

  11. 18

  12. 19

  13. 20

  14. 21

  15. Hosted Service PostgreSQL 22 BEGIN; SELECT FOR UPDATE FROM outbox_request

    WHERE status = Pending, next_attempt_date < now(); Kafka { "OutboxRequestId": 1 } Produce outbox_request.id UPDATE status = Processing; END;
  16. 23

  17. 24

  18. 25

  19. 26

  20. 27

  21. 28

  22. 29

  23. Kafka PostgreSQL Pod Handle SELECT FOR UPDATE FROM outbox_request WHERE

    status = Processing, id = :id outbox_request.id Consume UPDATE status = Handled/Failed/Pending, attempt_date = now() + interval 31
  24. 32

  25. 33

  26. 34

  27. 35

  28. 36

  29. 37

  30. 38

  31. 39

  32. 40

  33. 41

  34. 42

  35. 43

  36. Pod 1 Pod 3 Pod 2 45 Partition 0 Partition

    1 Partition 2 Kafka Pod leader Produce
  37. Pod 1 Pod 3 Pod 2 46 Shard 1 Bucket

    1 Bucket 2 Shard 2 Bucket 3 Bucket 4 Partition 0 Partition 1 Partition 2 Kafka Pod leader Produce
  38. 47 Shard 1 Bucket 1 Bucket 2 Shard 2 Bucket

    3 Bucket 4 Pod 3 Pod 2 etcd/Zookeper/Redis Pod 1