{"id":15,"date":"2026-07-06T20:34:58","date_gmt":"2026-07-06T20:34:58","guid":{"rendered":"https:\/\/kindsonthegenius.com\/microservices\/apache-kafka-microservices-topics-partitions\/"},"modified":"2026-07-06T20:36:16","modified_gmt":"2026-07-06T20:36:16","slug":"apache-kafka-microservices-topics-partitions","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/microservices\/apache-kafka-microservices-topics-partitions\/","title":{"rendered":"Apache Kafka for Microservices: Topics, Partitions &#038; Consumer Groups | Microservices Tutorials"},"content":{"rendered":"\n\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"Article\",\n  \"headline\": \"Apache Kafka for Microservices: Topics, Partitions &#038; Consumer Groups | Microservices Tutorials\",\n  \"url\": \"https:\/\/kindsonthegenius.com\/microservices\/apache-kafka-microservices-topics-partitions\/\",\n  \"description\": \"Apache Kafka tutorial for microservices: topics, partitions, consumer groups, retention, and ordering guarantees. Practical 2026 guide by Kindson.\",\n  \"datePublished\": \"2026-07-06\",\n  \"dateModified\": \"2026-07-06\",\n  \"author\": {\n    \"@type\": \"Person\",\n    \"name\": \"Kindson Munonye\",\n    \"url\": \"https:\/\/www.kindsonthegenius.com\"\n  },\n  \"publisher\": {\n    \"@type\": \"Organization\",\n    \"name\": \"Kindson The Genius\",\n    \"url\": \"https:\/\/www.kindsonthegenius.com\"\n  },\n  \"mainEntityOfPage\": \"https:\/\/kindsonthegenius.com\/microservices\/apache-kafka-microservices-topics-partitions\/\"\n}\n<\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Updated July 2026.<\/strong> Refreshed for current microservices best practices.<\/p>\n\n\n<h2 class=\"wp-block-heading\">Why Kafka in Microservices?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache Kafka is a distributed commit log that decouples producers from consumers. Unlike traditional message queues, Kafka retains events for configurable periods, supports replay, and scales horizontally \u2014 making it ideal for event-driven microservices and event sourcing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Core Concepts<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Topic<\/strong> \u2014 named stream of events (e.g., <code>orders<\/code>, <code>payments<\/code>).<\/li>\n<li><strong>Partition<\/strong> \u2014 ordered, immutable sequence within a topic. Parallelism unit.<\/li>\n<li><strong>Offset<\/strong> \u2014 position of a consumer within a partition.<\/li>\n<li><strong>Consumer group<\/strong> \u2014 consumers sharing work; one consumer per partition max.<\/li>\n<li><strong>Broker<\/strong> \u2014 Kafka server storing partitions.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Partition Key Strategy<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use aggregate ID (e.g., <code>orderId<\/code>) as the partition key so all events for one order stay ordered. Without keys, round-robin assignment breaks ordering guarantees.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Retention and Compaction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Time-based retention:<\/strong> keep events for 7 days (default).<br><strong>Log compaction:<\/strong> keep latest value per key \u2014 useful for changelog topics and snapshots.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Microservices Topic Design<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>One topic per aggregate type or bounded context.<\/li>\n<li>Use schema registry (Avro\/Protobuf) for contract evolution.<\/li>\n<li>Dead-letter topics for poison messages.<\/li>\n<li>Separate internal vs external event topics for API boundaries.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Related: <a href=\"\/microservices\/cqrs-pattern-microservices-kafka-2026\/\">CQRS with Kafka<\/a> \u00b7 <a href=\"\/microservices\/event-sourcing-explained-audit-ready-microservices\/\">Event Sourcing<\/a><\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Want live microservices classes?<\/strong> <a href=\"https:\/\/www.alkademy.com\/courses\/microservices-architecture-intermediate-design-communication-resilience\">Join Alkademy<\/a> for instructor-led microservices architecture courses with hands-on projects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Go deeper with the book:<\/strong> <a href=\"https:\/\/www.kindsonthegenius.com\/product\/practical-microservices-design-using-cqrs-and-event-sourcing\/\">Practical Microservices Design Using CQRS and Event Sourcing<\/a> by Kindson Munonye.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Kindson Munonye is a software engineer and technical author specializing in microservices, CQRS, event sourcing, and distributed systems. He publishes free step-by-step tutorials and live classes on <a href=\"https:\/\/www.alkademy.com\">Alkademy<\/a>.<\/em><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Apache Kafka tutorial for microservices: topics, partitions, consumer groups, retention, and ordering guarantees. Practical 2026 guide by Kindson.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-messaging-kafka"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"predecessor-version":[{"id":21,"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/posts\/15\/revisions\/21"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}