{"slug": "back-to-code-ep-13-event-driven-architecture-kafka-and-the-async-world", "title": "Back to Code | Ep 13: Event-Driven Architecture — Kafka and the Async World", "summary": "LogiFlow experienced a cascade failure when its invoice service crashed due to a memory leak, taking down the routing, tracking, and customer portal services because AI had connected them with synchronous HTTP calls. The team replaced the synchronous REST architecture with event-driven communication using Apache Kafka, where services publish domain events like \"RouteCalculated\" and consume them independently. This change isolates failures — when the invoice service goes down, events queue in Kafka and are processed upon recovery, preventing the domino effect that caused the 2 AM outage.", "body_md": "The 15-week technical battle of LogiFlow — a company waking up from the illusion created by artificial intelligence and returning to real engineering.\n\nWhen the \"Invoice\" service crashed, the \"Routing\" service also went down — because AI had connected them with synchronous HTTP (REST). **Cascade Failure.**\n\nIt was 2 AM when the pager went off. The invoice service had run out of memory — a memory leak in a PDF generation library. Within seconds, the routing service started timing out. Then the tracking service. Then the customer portal. One service's failure had cascaded through the entire system like dominoes.\n\n\"Why does the routing service care if invoicing is down?\" Defne asked, already knowing the answer.\n\n\"Because AI made routing call invoicing synchronously after every route calculation,\" Emre admitted.\n\n```\n// Routing service (Producer)\nawait kafka.send({\n  topic: 'routing.events',\n  messages: [{\n    key: truckId,\n    value: JSON.stringify({\n      type: 'RouteCalculated',\n      truckId,\n      eta,\n      timestamp: Date.now()\n    })\n  }]\n});\n\n// Invoice service (Consumer) — Runs independently\nconsumer.run({\n  eachMessage: async ({ message }) => {\n    const event = JSON.parse(message.value);\n    if (event.type === 'RouteCalculated') {\n      await generateInvoice(event);\n    }\n  }\n});\n```\n\n**Microservices should talk through Domain Events, not HTTP.**\n\nWhen the invoice service goes down now, the routing service doesn't notice. The events queue up in Kafka. When invoicing recovers, it processes the backlog. No cascade. No domino effect. No 2 AM pages.\n\n| Synchronous (HTTP) | Asynchronous (Events) |\n|---|---|\n| Caller waits for response | Fire and forget |\n| Failure cascades | Failure is isolated |\n| Tight coupling | Loose coupling |\n| Easy to reason about | Requires event schema design |\n| Simple for 2 services | Essential for 10+ services |\n\n**1. Loose Coupling:** Services should not wait for each other.\n\n**2. Domain Events:** 'RouteCalculated', 'InvoiceGenerated' — communicate through events.\n\n**3. Dead Letter Queue:** Failed messages should not be lost — they should wait in a separate queue for investigation and replay.\n\n*This is Episode 13 of the \"Back to Code\" series. Next up: Episode 14 — Technical Debt Credit Score.*\n\n*Series: back.to.code · 2026*", "url": "https://wpnews.pro/news/back-to-code-ep-13-event-driven-architecture-kafka-and-the-async-world", "canonical_source": "https://dev.to/turacthethinker/back-to-code-ep-13-event-driven-architecture-kafka-and-the-async-world-1f9p", "published_at": "2026-05-26 11:38:27+00:00", "updated_at": "2026-05-26 12:04:11.882949+00:00", "lang": "en", "topics": ["ai-infrastructure", "ai-tools", "ai-products", "ai-startups"], "entities": ["LogiFlow", "Kafka", "Defne", "Emre"], "alternates": {"html": "https://wpnews.pro/news/back-to-code-ep-13-event-driven-architecture-kafka-and-the-async-world", "markdown": "https://wpnews.pro/news/back-to-code-ep-13-event-driven-architecture-kafka-and-the-async-world.md", "text": "https://wpnews.pro/news/back-to-code-ep-13-event-driven-architecture-kafka-and-the-async-world.txt", "jsonld": "https://wpnews.pro/news/back-to-code-ep-13-event-driven-architecture-kafka-and-the-async-world.jsonld"}}