YouTube2Text

Kafka Tutorial for Beginners | Everything you need to get started — Transcript

by TechWorld with Nana · 2,796 words · 412 segments · language en · Watch on YouTube

Full transcript

  1. 0:00if you've been hearing about Kafka but
  2. 0:02you don't understand what it is and why
  3. 0:04all the hype let me clarify it using
  4. 0:08real life examples that will make
  5. 0:10everything finally click for you imagine
  6. 0:13we're building an e-commerce application
  7. 0:15called stream store and we have some
  8. 0:17microservices handling payments orders
  9. 0:20inventory and so on and when something
  10. 0:23happens in our application like customer
  11. 0:26places an order it's like dominoes where
  12. 0:28a chain reaction of updates and events
  13. 0:32by other services get triggered like
  14. 0:35stock needs to be updated in the
  15. 0:36database now that we sold some of it a
  16. 0:39notification or confirmation email needs
  17. 0:42to be sent to the customer an invoice
  18. 0:44needs to be generated with the right
  19. 0:46sales tax and sent per email to the
  20. 0:50customer um maybe revenue and sales data
  21. 0:53needs to be updated on our sales
  22. 0:54dashboard and so on now we are a small
  23. 0:58startup so we are starting with the
  24. 1:00simplest straightforward microservices
  25. 1:03architecture where the microservices
  26. 1:05just call each other like the order
  27. 1:07service would say hey all you guys we
  28. 1:10just closed an order go update your
  29. 1:12stuff accordingly and it all worked
  30. 1:15great at first but suddenly we become a
  31. 1:18hit and people are loving our store or
  32. 1:21we just announced Black Friday sales and
  33. 1:24our store is getting hundreds of
  34. 1:27thousands of customers which is amazing
  35. 1:30but suddenly our application starts
  36. 1:33crashing everything is slowing down
  37. 1:35users are sitting in front of loading
  38. 1:37screens because our architecture cannot
  39. 1:41handle this load we get in panic because
  40. 1:44we are losing cells every minute our
  41. 1:47architecture that looked pretty clean
  42. 1:50and straightforward on the Whiteboard
  43. 1:52becomes a nightmare so here is what's
  44. 1:55happening in the background first of all
  45. 1:57we have what's called tight coupling
  46. 1:59between the services which means when
  47. 2:02the payment service goes down for
  48. 2:04example because some API in the
  49. 2:06background isn't responsive or the
  50. 2:09service itself just crashes under load
  51. 2:11and when that happens our entire order
  52. 2:14process freezes we have synchronous
  53. 2:16communication so each order feels like a
  54. 2:18game of dominoes one slow service and
  55. 2:21everything backs up and as I said during
  56. 2:24peak times customers are literally
  57. 2:27staring at loading screens and we also
  58. 2:30have lots of single points of failure
  59. 2:32which means a 10-minute inventory
  60. 2:35service outage meant 2 hours of order
  61. 2:38backlogs and countless lost sales and we
  62. 2:40are also losing a lot of analytics data
  63. 2:43when the analytics service goes down for
  64. 2:44an hour we're losing important Black
  65. 2:47Friday sales data after another hectic
  66. 2:51and chaotic week we thought what if we
  67. 2:55redesign the system so that the orders
  68. 2:58flow through the system like items on a
  69. 3:01conveyor belt instead of our current
  70. 3:03game of hot potato and instead of apps
  71. 3:07calling each other directly and waiting
  72. 3:09for reply we remove that tide coupling
  73. 3:12we basically make space between them and
  74. 3:16introduce a tool that sits in the middle
  75. 3:19and acts as a broker think of it as post
  76. 3:22office when you order something online
  77. 3:25the sellers don't come knocking on your
  78. 3:27door to deliver package themselves
  79. 3:30they hand it over to the post office or
  80. 3:32some middleman to deliver your package
  81. 3:35or if you are returning your purchase or
  82. 3:38sending a package to someone you don't
  83. 3:40fly to their place to give them the
  84. 3:41package in person post office has this
  85. 3:44infrastructure and handles the
  86. 3:46processing so Kafka is like the mail
  87. 3:50delivery service or post office which
  88. 3:52sits in the middle so now the order
  89. 3:54service goes to Kafka and hands over a
  90. 3:57package called event that says
  91. 4:00hey order was made for this customer for
  92. 4:03these products and here are all the
  93. 4:05details please make this information
  94. 4:07available for anyone who needs it to
  95. 4:09update and do stuff in the background
  96. 4:11bye and it just basically goes back and
  97. 4:14continues its work and an event looks
  98. 4:17like this with very simple structure
  99. 4:19with key value pair and metadata
  100. 4:21information so the order service does
  101. 4:24not need to wait there to make sure that
  102. 4:26the others actually got the information
  103. 4:29it can trust this broker that it will be
  104. 4:32delivered to the right services and all
  105. 4:35this will happen in the background like
  106. 4:37in the post office you just drop off
  107. 4:39your package and go home you don't wait
  108. 4:41there sitting and checking whether they
  109. 4:44actually ship the package or not because
  110. 4:46you know that will take care of the rest
  111. 4:49and the order service that gives that
  112. 4:51information to Kafka or basically a
  113. 4:53service that produces this event and
  114. 4:56hands it over to kfka is called a
  115. 4:58producer because it produces events and
  116. 5:01in code this is how it would look like
  117. 5:03using Kafka producer API so in
  118. 5:06JavaScript or Java code you basically
  119. 5:08use that API to create an event and give
  120. 5:12it to CFA now where does this
  121. 5:15information or these events get saved
  122. 5:17when producers of those events give them
  123. 5:21to Kafka because we have bunch of other
  124. 5:23services like inventory payment and so
  125. 5:26on that also produce certain events and
  126. 5:28hand it over to kka with all the
  127. 5:31information that other services may need
  128. 5:33when inventory gets updated or the
  129. 5:35payment service says that the payment
  130. 5:37just failed and so on so do all these
  131. 5:39events from different producers get
  132. 5:42dumped into a giant bucket in Kafka or
  133. 5:45are they organized somehow if we had one
  134. 5:48big bucket handling all the rights and
  135. 5:51reads it will not be very performant
  136. 5:54right it's like having one single queue
  137. 5:56in the post office so if weather sending
  138. 6:00a letter or package or picking up your
  139. 6:02delivery everyone would be standing in
  140. 6:04the same queue instead imagine that post
  141. 6:08office will add sections with their own
  142. 6:11cues like a section for letters another
  143. 6:14one for large packages and so on so
  144. 6:17Kafka has what's called topics to group
  145. 6:21the same type of events so for example
  146. 6:24order service will write events to
  147. 6:27orders topic the payments service May
  148. 6:30update payments topic and so on now how
  149. 6:34do those topics get created or who
  150. 6:36defines them well just like you define a
  151. 6:39SQL schema for your database based on
  152. 6:42what your application needs and what
  153. 6:44objects you have you as an engineer
  154. 6:46decide how to group these events in
  155. 6:49Kafka in what topics so now that the
  156. 6:53order service added an event to the
  157. 6:55order topic what happens next that event
  158. 6:59May trigger other actions like updating
  159. 7:02stock in the database because we just
  160. 7:04sold something or sending notification
  161. 7:06to customer or updating invoice and
  162. 7:08sales status plus what other topics may
  163. 7:12exist that would need an event data
  164. 7:15entry as a result of an order which will
  165. 7:18in turn trigger other actions so how
  166. 7:22does all that get handled well on the
  167. 7:25other side of events we have consumers
  168. 7:29basic basically microservices who are
  169. 7:31subscribed to these different topics and
  170. 7:34whenever a new event happens and gets
  171. 7:37added to this topic all consumers who
  172. 7:40are subscribed get notified by Kafka and
  173. 7:44they then do their stuff in this case we
  174. 7:47have three microservices that subscribe
  175. 7:50to the order event notification service
  176. 7:53we'll see that a new order event was
  177. 7:55added which means a order was placed in
  178. 7:58our application
  179. 7:59and based on the payload of that event
  180. 8:02it will send a confirmation email to the
  181. 8:05customer and maybe a purchase
  182. 8:07notification to your email then an
  183. 8:09inventory service May update the
  184. 8:12database by updating the stocks of every
  185. 8:16product that was sold in that order and
  186. 8:19maybe in addition to that database
  187. 8:20update we'll generate a new event and
  188. 8:23write it into an inventory topic and
  189. 8:27then finally the payment service May
  190. 8:29generate invoice and send it to the user
  191. 8:32now I hope you're learning a lot and the
  192. 8:34topic of Kafka is becoming clear for you
  193. 8:36it takes us on average two or 3 weeks to
  194. 8:40produce one such video so if you find it
  195. 8:43valuable we would appreciate if you left
  196. 8:46your feedback or liked the video and
  197. 8:49we'd be happy to have you as our
  198. 8:51subscriber as well now you may be asking
  199. 8:54is kfka a replacement of a database
  200. 8:57somehow since we are SA saving all these
  201. 9:00data as events and basically updating
  202. 9:03the status of things so is it kind of a
  203. 9:06new way of saving things a simple answer
  204. 9:09is no it's not a replacement database
  205. 9:12let's explain by following our story so
  206. 9:14when the inventory service updates the
  207. 9:17stock for each product in the database
  208. 9:20why does it produce an event and write
  209. 9:22it to the inventory topic what kind of
  210. 9:25event that may be and why would we have
  211. 9:27it in addition to the dat in the
  212. 9:30database well that's another use case of
  213. 9:33kfka where one event basically creates
  214. 9:36this chain reaction of events when
  215. 9:39multiple things need to happen as a
  216. 9:40result of one event happening which we
  217. 9:43saw an example you may have another
  218. 9:45service that is subscribed to the
  219. 9:47inventory topic and calculates whether
  220. 9:50any of the products just gone below the
  221. 9:53inventory threshold and produce a low
  222. 9:55inventory alert which maybe as a chain
  223. 9:58reaction will trigger another service
  224. 10:01that may trigger an inventory restock
  225. 10:03service that will order more inventory
  226. 10:06of that specific product another very
  227. 10:08important use case of Kafka is realtime
  228. 10:12analytics for example again when sales
  229. 10:15happen in your application you may have
  230. 10:17a sales dashboard where your service is
  231. 10:20updating real time sales numbers and
  232. 10:23other such use case is driver location
  233. 10:25updates in an application like uber
  234. 10:27where the driver location
  235. 10:29changes get sent constantly to the
  236. 10:32application which then updates the UI of
  237. 10:35the user to display those changes and
  238. 10:38for all these use cases Kafka actually
  239. 10:41uses what's called Stream apis So on one
  240. 10:44side you have these regular consumers
  241. 10:47that will process one event at a time
  242. 10:50for example a notification service that
  243. 10:52will read an order event and based on
  244. 10:55that we'll send an email or notification
  245. 10:57to the customer streams on the other
  246. 11:00hand will process continuous flow of
  247. 11:03data with aggregations and joints and so
  248. 11:06on in order to do realtime processing
  249. 11:08and analytics on them so for example low
  250. 11:11inventory validations to check
  251. 11:14constantly with every event and do the
  252. 11:16calculation to see whether inventory
  253. 11:19just dropped below the threshold or get
  254. 11:22the location changes from the drivers so
  255. 11:26this analytic services will stream the
  256. 11:28events Contin ly doing various analytics
  257. 11:31and calculations on them and in code you
  258. 11:33would have a streams API that will read
  259. 11:36the orders and do all these kinds of
  260. 11:38calculations on them now as I mentioned
  261. 11:41these are streams of constant data saved
  262. 11:45as events in kfka because you have an
  263. 11:49application like uber with millions of
  264. 11:51users and tens of thousands of drivers
  265. 11:54with their locations getting updated
  266. 11:56constantly that's a lot of data and
  267. 11:58events that are being produced right and
  268. 12:01all consumers need to read from it so
  269. 12:04millions of writes and reads in
  270. 12:05different Kafka topics which can of
  271. 12:07course affect performance so we need to
  272. 12:10scale and that's where kafka's partition
  273. 12:13concept comes in which is kind of a core
  274. 12:15of kafka's ability to scale and become
  275. 12:17really performant so partitions are
  276. 12:20basically what make processing large
  277. 12:22amounts of data easy to handle and
  278. 12:24process without compromising the
  279. 12:26performance so how does it work exactly
  280. 12:29with our post office example remember we
  281. 12:32edit sections for letters large packages
  282. 12:35small packages and so on partitions are
  283. 12:38like adding more workers per section to
  284. 12:42help out so suddenly Before Christmas
  285. 12:44the letters section get overloaded
  286. 12:47because everyone's sending letters to
  287. 12:49centa well sadly that doesn't happen but
  288. 12:52if it did we would add more workers in
  289. 12:55that section but not just randomly
  290. 12:57instead you say an processes letters
  291. 13:00going to Europe Steve handle's letters
  292. 13:03to us Jay handle's ones to Asia and so
  293. 13:07on same way in Kafka in the orders topic
  294. 13:10you may create EU orders partition us
  295. 13:14orders Asia orders and so on and again
  296. 13:17you would decide how to partition your
  297. 13:19topic as part of your schema design now
  298. 13:23let's think about the consumer side
  299. 13:25let's say suddenly millions of orders
  300. 13:27are coming in and we said we can can
  301. 13:29scale this with partitions so producers
  302. 13:32can write into multiple partitions at
  303. 13:34the same time but what about the
  304. 13:36consumers how can they consume so much
  305. 13:38data at once because even if you have
  306. 13:41partitions you'll have one consumer
  307. 13:44let's say inventory service trying to
  308. 13:47process all the events that it's
  309. 13:49subscribed to which is like all the
  310. 13:52parcels going to one person recipient
  311. 13:56like thousands of letters going to Santa
  312. 13:59those post office workers are being
  313. 14:01super quick and are delivering them to
  314. 14:04the recipient but he's getting buried
  315. 14:07under the pile but we need some people
  316. 14:09helping him sort through this and that's
  317. 14:12where consumer groups come in so when
  318. 14:14you start additional instances of that
  319. 14:17microservice like replicas in kubernetes
  320. 14:20they can all consume from CFA partitions
  321. 14:23and process events faster in parallel
  322. 14:26now how does Kafka know which consumers
  323. 14:29form a group and how to divide and which
  324. 14:32ones Belong Together simple they are
  325. 14:35grouped by the group ID attribute when
  326. 14:37they register as consumers with kfka so
  327. 14:40replicas of the same application will
  328. 14:42have the same group IDs and will
  329. 14:44automatically be grouped together and
  330. 14:46when you start replicas Kafka
  331. 14:49distributes the load automatically by
  332. 14:52assigning partitions to Consumers so
  333. 14:55kfka says oh we have a new helper now
  334. 14:59you can process this pile of letters
  335. 15:01here and when that helper stops working
  336. 15:04it will take the pile and give it to
  337. 15:06another active one now the final
  338. 15:08question is where is this data
  339. 15:11physically saved data in topics is saved
  340. 15:15on CFA servers called Brokers and you
  341. 15:18can think of each broker like a post
  342. 15:20office branch that stores the actual
  343. 15:23messages on disk handles requests from
  344. 15:27producers and consumers and replicates
  345. 15:29the data for fault tolerance even if
  346. 15:32something happens with the dis the data
  347. 15:34is stored somewhere else as a backup and
  348. 15:37this is actually what makes Kafka
  349. 15:40different from standard message Brokers
  350. 15:44so while regular message cues would
  351. 15:46delete messages after consumption so as
  352. 15:49soon as consumers see that message and
  353. 15:52do something with it that message is
  354. 15:54gone kavka however persists every event
  355. 15:57or message as long as you need and you
  356. 15:59can configure how long you want to store
  357. 16:01them with a retention policy so think of
  358. 16:03it like our post office keeping a log of
  359. 16:07all package deliveries but not just for
  360. 16:10record keeping but for analyzing
  361. 16:12patterns and improving service so that
  362. 16:15unique feature of kfka for real-time
  363. 16:17data processing and general analytics
  364. 16:19means that kfka needs to store those
  365. 16:22events long-term so the consumers can
  366. 16:25read those events anytime they want even
  367. 16:28multi multiple times if they need to and
  368. 16:30as I said this capability to process
  369. 16:32streams of data in real time while
  370. 16:35keeping the original data for later
  371. 16:37analysis is what really differentiates
  372. 16:41Kafka from simple message Brokers so
  373. 16:44that's the main difference and for even
  374. 16:46clearer comparison think of this as
  375. 16:50difference between watching Netflix and
  376. 16:53watching TV Netflix is on demand so
  377. 16:56consumers or people who are the viewers
  378. 16:59can decide themselves what they want to
  379. 17:02watch when they want to watch it and at
  380. 17:04what pace so they can stop and pause
  381. 17:07anytime and continue whenever they want
  382. 17:10or they can replay or start from the
  383. 17:12beginning with TV you have predefined
  384. 17:16programs and people who want to view
  385. 17:18those programs need to tune in at
  386. 17:21specific time to watch specific stuff so
  387. 17:24everyone watches the same thing at the
  388. 17:26same time at the same Pace you can't
  389. 17:28pause and continue later if you miss a
  390. 17:31movie or show you just miss it and it's
  391. 17:33not automatically saved to watch later
  392. 17:36and that's exactly the difference
  393. 17:38between Kafka architecture versus other
  394. 17:41traditional message Brokers and finally
  395. 17:44Kafka needs a way to keep track of which
  396. 17:47Brokers are alive elect leaders to
  397. 17:49coordinate manage all the configuration
  398. 17:52and traditionally Kafka used an external
  399. 17:54tool called zookeeper for this type of
  400. 17:57coordination so it was like a central
  401. 18:00management for all the Kafka Brokers
  402. 18:03however important to note that the newer
  403. 18:06versions of Kafka from version 3.0
  404. 18:09introduced K raft or Kafka raft which
  405. 18:12removes the need for zookeeper as this
  406. 18:15external dependency with centralized
  407. 18:18control by building that coordination
  408. 18:20directly into Kafka now I hope I made
  409. 18:23Kafka finally clear for you share it
  410. 18:26with one colleague who you think will
  411. 18:28benefit from it and with that thanks for
  412. 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.