<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Preetham Tammana on Medium]]></title>
        <description><![CDATA[Stories by Preetham Tammana on Medium]]></description>
        <link>https://medium.com/@preetham.tammana?source=rss-7e8ddeda4347------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OzhWJFofa2qOcLK7</url>
            <title>Stories by Preetham Tammana on Medium</title>
            <link>https://medium.com/@preetham.tammana?source=rss-7e8ddeda4347------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:43:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@preetham.tammana/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Advanced System Design in Banking: Event-Driven Architecture with Kafka + CQRS]]></title>
            <link>https://medium.com/@preetham.tammana/advanced-system-design-in-banking-event-driven-architecture-with-kafka-cqrs-4a68413af35e?source=rss-7e8ddeda4347------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a68413af35e</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Preetham Tammana]]></dc:creator>
            <pubDate>Mon, 28 Apr 2025 06:27:00 GMT</pubDate>
            <atom:updated>2025-04-29T03:52:47.081Z</atom:updated>
            <content:encoded><![CDATA[<p>In the evolving landscape of financial technology, <strong>performance, scalability, and consistency</strong> are no longer just desirable — they are <em>essential</em>. Modern banking systems must reliably handle <strong>millions of transactions daily</strong>, ensure <strong>real-time responsiveness</strong>, and maintain <strong>strict auditability</strong> to comply with regulatory requirements.</p><p>To meet these demands, leading banks and financial institutions are embracing an elegant and robust design pattern:<br><strong>Event-Driven Architecture + CQRS (Command Query Responsibility Segregation) powered by Apache Kafka</strong>.</p><h3>Why This Architectural Approach?</h3><p>Traditionally, <strong>monolithic systems</strong> used a single relational database for both <strong>transaction processing</strong> and <strong>reporting queries</strong>.</p><p>This dual responsibility led to bottlenecks:</p><ol><li>Transactional workloads and reporting workloads would compete for database resources.</li><li>Scaling read-heavy operations required replicating the database or complex sharding.</li><li>Downtime or slowness during peak hours became common.</li></ol><p><strong>Event-Driven Architecture</strong> and <strong>CQRS</strong> cleanly solve this by <strong>separating concerns</strong> and leveraging <strong>asynchronous event flows</strong> to ensure smooth operation at scale.</p><p>Here’s why this pattern excels:</p><ol><li><strong>Separation of Command and Query Models</strong>: Write operations (commands) and read operations (queries) are handled by different models, allowing each to scale independently and be optimized for its purpose.</li><li><strong>High Throughput and Resiliency with Kafka</strong>: Apache Kafka acts as the central nervous system, decoupling producers and consumers, enabling back-pressure handling, retries, and durable storage of transaction events.</li><li><strong>Built-In Event Sourcing</strong>: Kafka’s ability to persist events allows reconstruction of system state at any point in time, crucial for auditability and compliance.</li></ol><h3>Real-World Banking Use Case: Handling Day-to-Day User Transactions</h3><p>## The sensitive information is encrypted and it is decrypted by necessary microservices.<br>## API Gateway writes the transaction.<br>## An event (TransactionCreatedEvent) is published to Kafka.<br>## Downstream services like fraud detection, balance updating, notifications, or reporting consume these events asynchronously.<br>## The read model is updated in a denormalized, optimized format for instant access (via NoSQL or cached views).</p><h3><strong>Sample Model , Consumer &amp; Producer:</strong></h3><pre>public class TransactionCreatedEvent {<br>    private String transactionId;<br>    private String fromAccount;<br>    private String toAccount;<br>    private double amount;<br>    private String currency;<br>    private long timestamp;<br><br>    // Getters and Setters<br>}</pre><pre>@Service<br>public class TransactionEventProducer {<br><br>    private final KafkaTemplate&lt;String, TransactionCreatedEvent&gt; kafkaTemplate;<br><br>    @Value(&quot;${banking.kafka.transaction-topic}&quot;)<br>    private String transactionTopic;<br><br>    public TransactionEventProducer(KafkaTemplate&lt;String, TransactionCreatedEvent&gt; kafkaTemplate) {<br>        this.kafkaTemplate = kafkaTemplate;<br>    }<br><br>    public void publishTransaction(TransactionCreatedEvent event) {<br>        kafkaTemplate.send(transactionTopic, event.getTransactionId(), event);<br>    }<br>}</pre><pre>@Service<br>public class BalanceUpdateService {<br><br>    @KafkaListener(topics = &quot;${banking.kafka.transaction-topic}&quot;, groupId = &quot;balance-update-group&quot;)<br>    public void consumeTransaction(TransactionCreatedEvent event) {<br>        System.out.println(&quot;Updating balances for transaction: &quot; + event.getTransactionId());<br>       <br>        debitAccount(event.getFromAccount(), event.getAmount());<br>        creditAccount(event.getToAccount(), event.getAmount());<br>    }<br><br>    private void debitAccount(String account, double amount) {<br>        // Logic to update account balance in DB<br>    }<br><br>    private void creditAccount(String account, double amount) {<br>        // Logic to update account balance in DB<br>    }<br>}</pre><h3>Benefits</h3><blockquote>Scalability and resilience<br>Near real-time updates<br>Fault-tolerant transaction pipelines<br>Easy integration of audit logs and compliance checks</blockquote><h3>Additional Best Practices in Building Such Systems</h3><p><strong>Idempotency</strong>: Ensure services are idempotent when consuming Kafka events to avoid duplicate processing during retries.<br><strong>Encryption and Tokenization</strong>: Sensitive information should always be encrypted at rest and in motion; tokenization can further minimize sensitive data exposure.<br><strong>Replay Capability</strong>: Design services to handle event replay gracefully (important for system restoration or onboarding new consumers).<br><strong>Schema Evolution</strong>: Use tools like <strong>Confluent Schema Registry</strong> to manage event schemas for forward/backward compatibility.<br><strong>Monitoring and Tracing</strong>: Implement distributed tracing (e.g., OpenTelemetry, Jaeger) across services to debug transaction flows end-to-end.</p><p>With this design, my main concern about how banks can perform millions of transactions each day has been resolved. Exposure to these types of architectures helps us stay current in a constantly evolving technological world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a68413af35e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>