Event-Driven Architecture - Building Scalable Systems With Apache Kafka - The Tal
Event-Driven Architecture - Building Scalable Systems With Apache Kafka - The Tal
Jump to
What is Event-Driven Architecture?
Key Concepts
Benefits of EDA
EDA vs Traditional Architectures
Apache Kafka: A Look at the Basics
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 1 of 19
:
Kafka Basics
Kafka Ecosystem
Use Cases
Setting Up Apache Kafka
Installation and Configuration
Configuration Details
Testing the Setup
Building a Producer Application
Producer Configuration
Advanced Producer Features
Building a Consumer Application
Consumer Configuration
Advanced Consumer Features
Stream Processing with Kafka Streams
Setting Up Kafka Streams
Writing a Kafka Streams Application
Monitoring and Managing Kafka
Logging and Alerting
Performance Tuning
Conclusion
Key Concepts
Event-Driven Architecture (EDA) revolves around the concept of events. An event is
a significant change in state that needs to be communicated within the system.
Here are some fundamental components:
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 2 of 19
:
Events: Represent state changes or significant occurrences within the system.
Event Producers: Generate events. For example, a user registration form submitting
a new user event.
Event Consumers: Process events. For example, a notification service that sends a
welcome email upon receiving a new user event.
Event Channels: Mediums through which events are transmitted, such as message
brokers like Kafka.
Benefits of EDA
EDA offers several advantages:
Scalability: Systems can handle high volumes of data and scale out by adding
more consumers.
Decoupling: Producers and consumers are loosely coupled, making the
system more flexible and easier to maintain.
Real-Time Processing: Events are processed as they occur, enabling real-time
analytics and responses.
Responsiveness: Systems can react promptly to changes and new data.
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 3 of 19
:
Kafka Basics
Apache Kafka is a distributed streaming platform designed for building real-time
data pipelines and streaming applications. Key components of Kafka include:
Brokers: Kafka servers that manage the storage and retrieval of data.
Kafka Ecosystem
Kafka’s ecosystem includes several powerful tools:
Kafka Connect: For integrating Kafka with various data sources and sinks.
Use Cases
Kafka is used in various industries:
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 4 of 19
:
bash
# Download Kafka
wget https://downloads.apache.org/kafka/2.7.0/kafka_2.13-2.7.0.tgz
cd kafka_2.13-2.7.0
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
Configuration Details
Key configuration parameters include:
Log Directories: Directories where Kafka stores data. Job Interview Guides
Let’s create a topic and test our Kafka setup with a simple producer and consumer:
bash
# Create a topic
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 5 of 19
:
# Start a producer
# Start a consumer
After running these commands, you can type messages into the producer console,
and they should appear in the consumer console.
Producer Configuration
Producers need to be configured with properties such as the Kafka broker address
and serializers for keys and values.
java
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;
props.put(“bootstrap.servers”, “localhost:9092”);
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 6 of 19
:
props.put(“key.serializer”,
“org.apache.kafka.common.serialization.StringSerializer”);
props.put(“value.serializer”,
“org.apache.kafka.common.serialization.StringSerializer”);
producer.close();
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 7 of 19
:
deserializers.
java
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import java.util.Collections;
import java.util.Properties;
props.put(“bootstrap.servers”, “localhost:9092”);
props.put(“group.id”, “test-group”);
props.put(“key.deserializer”,
“org.apache.kafka.common.serialization.StringDeserializer”);
props.put(“value.deserializer”,
“org.apache.kafka.common.serialization.StringDeserializer”);
consumer.subscribe(Collections.singletonList(“test-topic”));
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 8 of 19
:
while (true) {
Managing Offsets: Manually controlling the position of the consumer in the stream.
xml
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 9 of 19
:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>2.7.0</version>
</dependency>
java
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.kstream.KStream;
import org.apache.kafka.streams.kstream.KTable;
import org.apache.kafka.streams.kstream.Produced;
import java.util.Arrays;
import java.util.Properties;
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 10 of 19
:
public static void main(String[] args) {
props.put(StreamsConfig.APPLICATION_ID_CONFIG, “wordcount-
application”);
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, “localhost:9092”);
props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG,
Serdes.String().getClass());
props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG,
Serdes.String().getClass());
.count();
wordCounts.toStream().to(“WordsWithCountsTopic”,
Produced.with(Serdes.String(), Serdes.Long()));
streams.start();
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 11 of 19
:
Monitoring and Managing Kafka
Monitoring Kafka is essential to ensure its smooth operation. Some popular tools
include:
Performance Tuning
Optimize Kafka performance by:
Configuration Tuning: Adjusting parameters like batch size, linger time, and buffer
memory for producers.
Conclusion
In this blog, we have explored the fundamentals of Event-Driven Architecture and
how Apache Kafka serves as a powerful tool for building scalable systems. We
covered the basics of Kafka, from setting it up to building producer and consumer
applications, and even delved into stream processing with Kafka Streams. By
implementing EDA with Kafka, you can create responsive, real-time systems
capable of handling large volumes of data efficiently.
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 12 of 19
:
1+
Fa Li T W M P Pi Te G C
ce n wi h es o nt le m o
Taniya Pan
Add comment
Comment
Name *
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 13 of 19
:
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
SUBMIT COMMENT
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 14 of 19
:
Data Monitoring and Troubleshooting:
Monitoring Pipelines and Systems, and
Resolving...
DATA ANALYTICS
Categories
Analytics
Automation Testing
Backend
.Net
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 15 of 19
:
java
Python
career
Careers
cyber security
Data Analytics
data science
data architecture
data engineering
Enterprise
Frontend
Angular
JavaScript
React
Vue
Fullstack
Java + React
Node + React
general tech
Information Security
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 16 of 19
:
Information Security
Javascript
Job Search
Manual Testing
Mobile
android
iOS
Productivity
Workplace Communication
Manual Testing
Remote Working
Software Engineering
Technology
Artificial Intelligence
Augmented Reality
Data Science
Data Analytics
Developer Guides
DevOps
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 17 of 19
:
Java
Trends
Virtual Reality
Websites
Recent Posts
RSS feed
Fe
e
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 18 of 19
:
Talent500 helps the world’s fastest growing businesses build
their global workforce.
Follow Us
Home
Discover jobs
Enterprise blog
Professionals blog
About us
Terms of use
Privacy policy
Contact us
https://talent500.co/blog/event-driven-architecture-building-scalable-systems-with-apache-kafka/ 30/08/24, 11 39 AM
Page 19 of 19
: