Kafka Tutorial for Beginners | Everything you need to get started — Transcript
Full transcript
- 0:00if you've been hearing about Kafka but
- 0:02you don't understand what it is and why
- 0:04all the hype let me clarify it using
- 0:08real life examples that will make
- 0:10everything finally click for you imagine
- 0:13we're building an e-commerce application
- 0:15called stream store and we have some
- 0:17microservices handling payments orders
- 0:20inventory and so on and when something
- 0:23happens in our application like customer
- 0:26places an order it's like dominoes where
- 0:28a chain reaction of updates and events
- 0:32by other services get triggered like
- 0:35stock needs to be updated in the
- 0:36database now that we sold some of it a
- 0:39notification or confirmation email needs
- 0:42to be sent to the customer an invoice
- 0:44needs to be generated with the right
- 0:46sales tax and sent per email to the
- 0:50customer um maybe revenue and sales data
- 0:53needs to be updated on our sales
- 0:54dashboard and so on now we are a small
- 0:58startup so we are starting with the
- 1:00simplest straightforward microservices
- 1:03architecture where the microservices
- 1:05just call each other like the order
- 1:07service would say hey all you guys we
- 1:10just closed an order go update your
- 1:12stuff accordingly and it all worked
- 1:15great at first but suddenly we become a
- 1:18hit and people are loving our store or
- 1:21we just announced Black Friday sales and
- 1:24our store is getting hundreds of
- 1:27thousands of customers which is amazing
- 1:30but suddenly our application starts
- 1:33crashing everything is slowing down
- 1:35users are sitting in front of loading
- 1:37screens because our architecture cannot
- 1:41handle this load we get in panic because
- 1:44we are losing cells every minute our
- 1:47architecture that looked pretty clean
- 1:50and straightforward on the Whiteboard
- 1:52becomes a nightmare so here is what's
- 1:55happening in the background first of all
- 1:57we have what's called tight coupling
- 1:59between the services which means when
- 2:02the payment service goes down for
- 2:04example because some API in the
- 2:06background isn't responsive or the
- 2:09service itself just crashes under load
- 2:11and when that happens our entire order
- 2:14process freezes we have synchronous
- 2:16communication so each order feels like a
- 2:18game of dominoes one slow service and
- 2:21everything backs up and as I said during
- 2:24peak times customers are literally
- 2:27staring at loading screens and we also
- 2:30have lots of single points of failure
- 2:32which means a 10-minute inventory
- 2:35service outage meant 2 hours of order
- 2:38backlogs and countless lost sales and we
- 2:40are also losing a lot of analytics data
- 2:43when the analytics service goes down for
- 2:44an hour we're losing important Black
- 2:47Friday sales data after another hectic
- 2:51and chaotic week we thought what if we
- 2:55redesign the system so that the orders
- 2:58flow through the system like items on a
- 3:01conveyor belt instead of our current
- 3:03game of hot potato and instead of apps
- 3:07calling each other directly and waiting
- 3:09for reply we remove that tide coupling
- 3:12we basically make space between them and
- 3:16introduce a tool that sits in the middle
- 3:19and acts as a broker think of it as post
- 3:22office when you order something online
- 3:25the sellers don't come knocking on your
- 3:27door to deliver package themselves
- 3:30they hand it over to the post office or
- 3:32some middleman to deliver your package
- 3:35or if you are returning your purchase or
- 3:38sending a package to someone you don't
- 3:40fly to their place to give them the
- 3:41package in person post office has this
- 3:44infrastructure and handles the
- 3:46processing so Kafka is like the mail
- 3:50delivery service or post office which
- 3:52sits in the middle so now the order
- 3:54service goes to Kafka and hands over a
- 3:57package called event that says
- 4:00hey order was made for this customer for
- 4:03these products and here are all the
- 4:05details please make this information
- 4:07available for anyone who needs it to
- 4:09update and do stuff in the background
- 4:11bye and it just basically goes back and
- 4:14continues its work and an event looks
- 4:17like this with very simple structure
- 4:19with key value pair and metadata
- 4:21information so the order service does
- 4:24not need to wait there to make sure that
- 4:26the others actually got the information
- 4:29it can trust this broker that it will be
- 4:32delivered to the right services and all
- 4:35this will happen in the background like
- 4:37in the post office you just drop off
- 4:39your package and go home you don't wait
- 4:41there sitting and checking whether they
- 4:44actually ship the package or not because
- 4:46you know that will take care of the rest
- 4:49and the order service that gives that
- 4:51information to Kafka or basically a
- 4:53service that produces this event and
- 4:56hands it over to kfka is called a
- 4:58producer because it produces events and
- 5:01in code this is how it would look like
- 5:03using Kafka producer API so in
- 5:06JavaScript or Java code you basically
- 5:08use that API to create an event and give
- 5:12it to CFA now where does this
- 5:15information or these events get saved
- 5:17when producers of those events give them
- 5:21to Kafka because we have bunch of other
- 5:23services like inventory payment and so
- 5:26on that also produce certain events and
- 5:28hand it over to kka with all the
- 5:31information that other services may need
- 5:33when inventory gets updated or the
- 5:35payment service says that the payment
- 5:37just failed and so on so do all these
- 5:39events from different producers get
- 5:42dumped into a giant bucket in Kafka or
- 5:45are they organized somehow if we had one
- 5:48big bucket handling all the rights and
- 5:51reads it will not be very performant
- 5:54right it's like having one single queue
- 5:56in the post office so if weather sending
- 6:00a letter or package or picking up your
- 6:02delivery everyone would be standing in
- 6:04the same queue instead imagine that post
- 6:08office will add sections with their own
- 6:11cues like a section for letters another
- 6:14one for large packages and so on so
- 6:17Kafka has what's called topics to group
- 6:21the same type of events so for example
- 6:24order service will write events to
- 6:27orders topic the payments service May
- 6:30update payments topic and so on now how
- 6:34do those topics get created or who
- 6:36defines them well just like you define a
- 6:39SQL schema for your database based on
- 6:42what your application needs and what
- 6:44objects you have you as an engineer
- 6:46decide how to group these events in
- 6:49Kafka in what topics so now that the
- 6:53order service added an event to the
- 6:55order topic what happens next that event
- 6:59May trigger other actions like updating
- 7:02stock in the database because we just
- 7:04sold something or sending notification
- 7:06to customer or updating invoice and
- 7:08sales status plus what other topics may
- 7:12exist that would need an event data
- 7:15entry as a result of an order which will
- 7:18in turn trigger other actions so how
- 7:22does all that get handled well on the
- 7:25other side of events we have consumers
- 7:29basic basically microservices who are
- 7:31subscribed to these different topics and
- 7:34whenever a new event happens and gets
- 7:37added to this topic all consumers who
- 7:40are subscribed get notified by Kafka and
- 7:44they then do their stuff in this case we
- 7:47have three microservices that subscribe
- 7:50to the order event notification service
- 7:53we'll see that a new order event was
- 7:55added which means a order was placed in
- 7:58our application
- 7:59and based on the payload of that event
- 8:02it will send a confirmation email to the
- 8:05customer and maybe a purchase
- 8:07notification to your email then an
- 8:09inventory service May update the
- 8:12database by updating the stocks of every
- 8:16product that was sold in that order and
- 8:19maybe in addition to that database
- 8:20update we'll generate a new event and
- 8:23write it into an inventory topic and
- 8:27then finally the payment service May
- 8:29generate invoice and send it to the user
- 8:32now I hope you're learning a lot and the
- 8:34topic of Kafka is becoming clear for you
- 8:36it takes us on average two or 3 weeks to
- 8:40produce one such video so if you find it
- 8:43valuable we would appreciate if you left
- 8:46your feedback or liked the video and
- 8:49we'd be happy to have you as our
- 8:51subscriber as well now you may be asking
- 8:54is kfka a replacement of a database
- 8:57somehow since we are SA saving all these
- 9:00data as events and basically updating
- 9:03the status of things so is it kind of a
- 9:06new way of saving things a simple answer
- 9:09is no it's not a replacement database
- 9:12let's explain by following our story so
- 9:14when the inventory service updates the
- 9:17stock for each product in the database
- 9:20why does it produce an event and write
- 9:22it to the inventory topic what kind of
- 9:25event that may be and why would we have
- 9:27it in addition to the dat in the
- 9:30database well that's another use case of
- 9:33kfka where one event basically creates
- 9:36this chain reaction of events when
- 9:39multiple things need to happen as a
- 9:40result of one event happening which we
- 9:43saw an example you may have another
- 9:45service that is subscribed to the
- 9:47inventory topic and calculates whether
- 9:50any of the products just gone below the
- 9:53inventory threshold and produce a low
- 9:55inventory alert which maybe as a chain
- 9:58reaction will trigger another service
- 10:01that may trigger an inventory restock
- 10:03service that will order more inventory
- 10:06of that specific product another very
- 10:08important use case of Kafka is realtime
- 10:12analytics for example again when sales
- 10:15happen in your application you may have
- 10:17a sales dashboard where your service is
- 10:20updating real time sales numbers and
- 10:23other such use case is driver location
- 10:25updates in an application like uber
- 10:27where the driver location
- 10:29changes get sent constantly to the
- 10:32application which then updates the UI of
- 10:35the user to display those changes and
- 10:38for all these use cases Kafka actually
- 10:41uses what's called Stream apis So on one
- 10:44side you have these regular consumers
- 10:47that will process one event at a time
- 10:50for example a notification service that
- 10:52will read an order event and based on
- 10:55that we'll send an email or notification
- 10:57to the customer streams on the other
- 11:00hand will process continuous flow of
- 11:03data with aggregations and joints and so
- 11:06on in order to do realtime processing
- 11:08and analytics on them so for example low
- 11:11inventory validations to check
- 11:14constantly with every event and do the
- 11:16calculation to see whether inventory
- 11:19just dropped below the threshold or get
- 11:22the location changes from the drivers so
- 11:26this analytic services will stream the
- 11:28events Contin ly doing various analytics
- 11:31and calculations on them and in code you
- 11:33would have a streams API that will read
- 11:36the orders and do all these kinds of
- 11:38calculations on them now as I mentioned
- 11:41these are streams of constant data saved
- 11:45as events in kfka because you have an
- 11:49application like uber with millions of
- 11:51users and tens of thousands of drivers
- 11:54with their locations getting updated
- 11:56constantly that's a lot of data and
- 11:58events that are being produced right and
- 12:01all consumers need to read from it so
- 12:04millions of writes and reads in
- 12:05different Kafka topics which can of
- 12:07course affect performance so we need to
- 12:10scale and that's where kafka's partition
- 12:13concept comes in which is kind of a core
- 12:15of kafka's ability to scale and become
- 12:17really performant so partitions are
- 12:20basically what make processing large
- 12:22amounts of data easy to handle and
- 12:24process without compromising the
- 12:26performance so how does it work exactly
- 12:29with our post office example remember we
- 12:32edit sections for letters large packages
- 12:35small packages and so on partitions are
- 12:38like adding more workers per section to
- 12:42help out so suddenly Before Christmas
- 12:44the letters section get overloaded
- 12:47because everyone's sending letters to
- 12:49centa well sadly that doesn't happen but
- 12:52if it did we would add more workers in
- 12:55that section but not just randomly
- 12:57instead you say an processes letters
- 13:00going to Europe Steve handle's letters
- 13:03to us Jay handle's ones to Asia and so
- 13:07on same way in Kafka in the orders topic
- 13:10you may create EU orders partition us
- 13:14orders Asia orders and so on and again
- 13:17you would decide how to partition your
- 13:19topic as part of your schema design now
- 13:23let's think about the consumer side
- 13:25let's say suddenly millions of orders
- 13:27are coming in and we said we can can
- 13:29scale this with partitions so producers
- 13:32can write into multiple partitions at
- 13:34the same time but what about the
- 13:36consumers how can they consume so much
- 13:38data at once because even if you have
- 13:41partitions you'll have one consumer
- 13:44let's say inventory service trying to
- 13:47process all the events that it's
- 13:49subscribed to which is like all the
- 13:52parcels going to one person recipient
- 13:56like thousands of letters going to Santa
- 13:59those post office workers are being
- 14:01super quick and are delivering them to
- 14:04the recipient but he's getting buried
- 14:07under the pile but we need some people
- 14:09helping him sort through this and that's
- 14:12where consumer groups come in so when
- 14:14you start additional instances of that
- 14:17microservice like replicas in kubernetes
- 14:20they can all consume from CFA partitions
- 14:23and process events faster in parallel
- 14:26now how does Kafka know which consumers
- 14:29form a group and how to divide and which
- 14:32ones Belong Together simple they are
- 14:35grouped by the group ID attribute when
- 14:37they register as consumers with kfka so
- 14:40replicas of the same application will
- 14:42have the same group IDs and will
- 14:44automatically be grouped together and
- 14:46when you start replicas Kafka
- 14:49distributes the load automatically by
- 14:52assigning partitions to Consumers so
- 14:55kfka says oh we have a new helper now
- 14:59you can process this pile of letters
- 15:01here and when that helper stops working
- 15:04it will take the pile and give it to
- 15:06another active one now the final
- 15:08question is where is this data
- 15:11physically saved data in topics is saved
- 15:15on CFA servers called Brokers and you
- 15:18can think of each broker like a post
- 15:20office branch that stores the actual
- 15:23messages on disk handles requests from
- 15:27producers and consumers and replicates
- 15:29the data for fault tolerance even if
- 15:32something happens with the dis the data
- 15:34is stored somewhere else as a backup and
- 15:37this is actually what makes Kafka
- 15:40different from standard message Brokers
- 15:44so while regular message cues would
- 15:46delete messages after consumption so as
- 15:49soon as consumers see that message and
- 15:52do something with it that message is
- 15:54gone kavka however persists every event
- 15:57or message as long as you need and you
- 15:59can configure how long you want to store
- 16:01them with a retention policy so think of
- 16:03it like our post office keeping a log of
- 16:07all package deliveries but not just for
- 16:10record keeping but for analyzing
- 16:12patterns and improving service so that
- 16:15unique feature of kfka for real-time
- 16:17data processing and general analytics
- 16:19means that kfka needs to store those
- 16:22events long-term so the consumers can
- 16:25read those events anytime they want even
- 16:28multi multiple times if they need to and
- 16:30as I said this capability to process
- 16:32streams of data in real time while
- 16:35keeping the original data for later
- 16:37analysis is what really differentiates
- 16:41Kafka from simple message Brokers so
- 16:44that's the main difference and for even
- 16:46clearer comparison think of this as
- 16:50difference between watching Netflix and
- 16:53watching TV Netflix is on demand so
- 16:56consumers or people who are the viewers
- 16:59can decide themselves what they want to
- 17:02watch when they want to watch it and at
- 17:04what pace so they can stop and pause
- 17:07anytime and continue whenever they want
- 17:10or they can replay or start from the
- 17:12beginning with TV you have predefined
- 17:16programs and people who want to view
- 17:18those programs need to tune in at
- 17:21specific time to watch specific stuff so
- 17:24everyone watches the same thing at the
- 17:26same time at the same Pace you can't
- 17:28pause and continue later if you miss a
- 17:31movie or show you just miss it and it's
- 17:33not automatically saved to watch later
- 17:36and that's exactly the difference
- 17:38between Kafka architecture versus other
- 17:41traditional message Brokers and finally
- 17:44Kafka needs a way to keep track of which
- 17:47Brokers are alive elect leaders to
- 17:49coordinate manage all the configuration
- 17:52and traditionally Kafka used an external
- 17:54tool called zookeeper for this type of
- 17:57coordination so it was like a central
- 18:00management for all the Kafka Brokers
- 18:03however important to note that the newer
- 18:06versions of Kafka from version 3.0
- 18:09introduced K raft or Kafka raft which
- 18:12removes the need for zookeeper as this
- 18:15external dependency with centralized
- 18:18control by building that coordination
- 18:20directly into Kafka now I hope I made
- 18:23Kafka finally clear for you share it
- 18:26with one colleague who you think will
- 18:28benefit from it and with that thanks for
- 18:30watching and see you in the next video
About this transcript
This page contains the full transcript of Kafka Tutorial for Beginners | Everything you need to get started by TechWorld with Nana, generated from the public captions YouTube serves with the video. The transcript has 2,796 words across 412 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.