<?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 Lamaelmalatawy on Medium]]></title>
        <description><![CDATA[Stories by Lamaelmalatawy on Medium]]></description>
        <link>https://medium.com/@lamaelmalatawy?source=rss-a6bbe0eec3d9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*g18vZwpp4Jweebk5jhn35g.jpeg</url>
            <title>Stories by Lamaelmalatawy on Medium</title>
            <link>https://medium.com/@lamaelmalatawy?source=rss-a6bbe0eec3d9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:08:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lamaelmalatawy/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[⚙️Algorithmic Patterns Every Developer Must Know]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://blog.stackademic.com/%EF%B8%8Falgorithmic-patterns-every-developer-must-know-3c7e3f3cd108?source=rss-a6bbe0eec3d9------2"><img src="https://cdn-images-1.medium.com/max/1536/1*zKaUPkQXt1lJPhGbKVM-tg.png" width="1536"></a></p><p class="medium-feed-snippet">Not a member? Click here to read the full article.</p><p class="medium-feed-link"><a href="https://blog.stackademic.com/%EF%B8%8Falgorithmic-patterns-every-developer-must-know-3c7e3f3cd108?source=rss-a6bbe0eec3d9------2">Continue reading on Stackademic »</a></p></div>]]></description>
            <link>https://blog.stackademic.com/%EF%B8%8Falgorithmic-patterns-every-developer-must-know-3c7e3f3cd108?source=rss-a6bbe0eec3d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c7e3f3cd108</guid>
            <category><![CDATA[backtracking]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[patterns]]></category>
            <dc:creator><![CDATA[Lamaelmalatawy]]></dc:creator>
            <pubDate>Wed, 06 May 2026 06:56:50 GMT</pubDate>
            <atom:updated>2026-05-06T10:19:23.961Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[ The Hidden Engines Behind Your Apps: Data Structures in Java]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://blog.stackademic.com/the-hidden-engines-behind-your-apps-data-structures-in-java-b3619ee973b2?source=rss-a6bbe0eec3d9------2"><img src="https://cdn-images-1.medium.com/max/1024/1*D3uacBHd2slZT34yL5E7_A.jpeg" width="1024"></a></p><p class="medium-feed-snippet">Every time Instagram ranks posts, TikTok recommends the next video, or Spotify manages your playlist&#x200A;&#x2014;&#x200A;it&#x2019;s not luck. It&#x2019;s data structures.</p><p class="medium-feed-link"><a href="https://blog.stackademic.com/the-hidden-engines-behind-your-apps-data-structures-in-java-b3619ee973b2?source=rss-a6bbe0eec3d9------2">Continue reading on Stackademic »</a></p></div>]]></description>
            <link>https://blog.stackademic.com/the-hidden-engines-behind-your-apps-data-structures-in-java-b3619ee973b2?source=rss-a6bbe0eec3d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3619ee973b2</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[full-stack-developer]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[social-media]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Lamaelmalatawy]]></dc:creator>
            <pubDate>Sun, 19 Oct 2025 19:47:21 GMT</pubDate>
            <atom:updated>2025-10-20T11:57:00.283Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Database 101]]></title>
            <link>https://medium.com/@lamaelmalatawy/database-101-1ec12829dd53?source=rss-a6bbe0eec3d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ec12829dd53</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Lamaelmalatawy]]></dc:creator>
            <pubDate>Tue, 06 May 2025 13:31:33 GMT</pubDate>
            <atom:updated>2025-05-09T10:01:12.618Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Whether you’re preparing for a tech interview or brushing up on core concepts, this guide covers essential database knowledge for software engineers.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y9arekhIcCJ5A87mOJyp_g.png" /></figure><h3>What is a DBMS?</h3><p>A<strong> Database Management System</strong> is a software that allows for the creation, retrieval, update, and management of data in databases. It provides an interface between users and data, ensuring data is consistently organized and remains easily accessible.</p><h4>Types of databases</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*joOW9d34Jxv5ORtqGtTCGQ.png" /><figcaption>Relational vs NoSQL databases</figcaption></figure><h3>Core SQL Concepts</h3><h4>Data Definition Language (DDL)</h4><ul><li>CREATE: Create new tables, indexes, schemas</li></ul><pre>CREATE TABLE users (<br>  id INT PRIMARY KEY,<br>  name VARCHAR(100),<br>  email VARCHAR(100) UNIQUE<br>);</pre><ul><li>ALTER: Modify existing database structures</li></ul><pre>ALTER TABLE users <br>ADD birth_date DATE;</pre><ul><li>DROP: Remove tables or other structures</li></ul><pre>DROP TABLE users;</pre><ul><li>TRUNCATE: Remove all data from a table without logging individual row deletions</li></ul><pre>TRUNCATE TABLE users;</pre><h4>Data Manipulation Language (DML)</h4><ul><li>SELECT: Retrieve data</li></ul><pre>SELECT * FROM users;</pre><ul><li>UNION: Combines the result set of two or more SELECT statements.</li></ul><pre>SELECT name FROM users<br>UNION<br>SELECT employee_name FROM employees;</pre><ul><li>INSERT: Add new rows</li></ul><pre>INSERT INTO users (id, name, email) <br>VALUES (1, &#39;Alice&#39;, &#39;alice@example.com&#39;);</pre><ul><li>UPDATE: Modify existing data</li></ul><pre>UPDATE users<br>SET email = &#39;alice1@example.com&#39;<br>WHERE id = 1;</pre><ul><li>DELETE: Remove data</li></ul><pre>DELETE FROM users<br>WHERE id = 1;</pre><h4>Data Control Language (DCL)</h4><ul><li>GRANT: Give user access privileges</li></ul><pre>GRANT SELECT, INSERT ON users TO &#39;dev_user&#39;;</pre><ul><li>REVOKE: Remove user privileges</li></ul><pre>REVOKE INSERT ON users FROM &#39;dev_user&#39;;</pre><h4>Transaction Control</h4><ul><li>BEGIN / START TRANSACTION: Begin a new transaction</li><li>COMMIT: Save changes</li></ul><pre>BEGIN;<br>UPDATE users SET email = &#39;dev@user.com&#39; WHERE id = 2;<br>SELECT * FROM users where id = 3;<br>COMMIT;</pre><ul><li>ROLLBACK: Revert to last consistent state</li></ul><pre>START TRANSACTION;<br>UPDATE users SET name = &#39;Bob&#39; WHERE id = 1;<br>ROLLBACK; -- name will not be updated</pre><ul><li>SAVEPOINT, ROLLBACK TO: Intermediate transaction save markers</li></ul><pre>BEGIN;  -- Start a transaction<br><br>UPDATE accounts SET balance = balance - 100 WHERE account_id = 1;<br><br>SAVEPOINT before_deposit;  -- Create a savepoint<br><br>UPDATE accounts SET balance = balance + 100 WHERE account_id = 2;<br><br>-- Oops! Suppose something goes wrong, like a constraint violation.<br>-- You decide to roll back only to the savepoint:<br><br>ROLLBACK TO before_deposit;<br><br>-- Now you can continue with other operations or end the transaction<br>COMMIT;</pre><p>Comparison between <strong>DROP</strong>, <strong>DELETE</strong>, and <strong>TRUNCATE</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ARsik8VWEUr_bNW2PHbMg.jpeg" /><figcaption>DELETE vs DROP vs TRUNCATE</figcaption></figure><h3>ACID Properties</h3><p>Set of guarantees that ensure database transactions are processed reliably.</p><ol><li><strong>Atomicity</strong>: Each transaction is all-or-nothing. If any part fails, the entire transaction fails.</li></ol><blockquote><strong><em>Example</em></strong><em>:</em> If a transaction T consists of T1 and T2, both of them must succeed for the transaction to be successful</blockquote><p>2.<strong> Consistency</strong>: Ensures that the database remains in a valid state before and after the transaction.</p><blockquote><strong><em>Example</em></strong><em>:</em> Prevent transferring money that leads to a negative balance when the schema requires a non-negative constraint.</blockquote><p>3. <strong>Isolation</strong>: Concurrent transactions do not interfere with each other.</p><blockquote><strong><em>Example</em></strong><em>:</em> Two users booking the last seat on a flight shouldn’t both succeed.</blockquote><p>4. <strong>Durability</strong>: Once a transaction is committed, it remains even after a crash.</p><blockquote><strong><em>Example</em></strong><em>:</em> Power failure after a COMMIT won&#39;t undo the transaction.</blockquote><h3>Isolation Levels</h3><p>Isolation levels define how transactions interact with each other. They help control <strong>concurrency</strong> and prevent undesirable effects like dirty reads or lost updates.</p><p>We mainly have <strong>3 anomalies:</strong></p><ol><li><strong>Dirty Reads:</strong><br>Reading uncommitted data from another transaction.</li><li><strong>Non-repeatable Reads:</strong><br>Same query returns different results within one transaction.</li><li><strong>Phantom Read</strong>:<br>New rows added by another transaction affect results of a re-run query</li></ol><p>So SQL defined <strong>four standard isolation levels:</strong></p><h4>1. Read Uncommitted</h4><p>Lowest level of isolation. Transactions can read data modified by other uncommitted transactions (dirty reads).</p><ul><li><strong>Problem</strong>: Allows dirty reads</li><li><strong>Use case</strong>: Rarely recommended unless performance is prioritized over accuracy</li></ul><pre>SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;</pre><h4>2. Read Committed</h4><p>A transaction only reads committed data. <strong>Prevents</strong> dirty reads, <strong>but</strong> non-repeatable reads can still occur (i.e., data changes between reads).</p><ul><li><strong>Problem</strong>: Allows non-repeatable reads</li><li><strong>Default in</strong>: SQL Server, Oracle</li></ul><pre>SET TRANSACTION ISOLATION LEVEL READ COMMITTED;</pre><h4>3. Repeatable Read</h4><p>Ensures rows read in a transaction cannot change or be deleted. <strong>Prevents</strong> dirty and non-repeatable reads, <strong>but</strong> phantom reads may still occur (new rows being added).</p><ul><li><strong>Problem</strong>: Allows phantom reads</li><li><strong>Default in</strong>: MySQL</li></ul><pre>SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;</pre><h4>4. Serializable</h4><p>Highest level of isolation. Acts as if transactions run sequentially. <strong>Prevents</strong> dirty reads, non-repeatable reads, and phantom reads.</p><ul><li><strong>Problem</strong>: Highest locking, lowest concurrency</li><li><strong>Use case</strong>: When strict consistency is needed</li></ul><pre>SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;</pre><h3>Indexing</h3><p>Indexes speed up data retrieval at the cost of additional storage and slower writes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KY5t-CyEoeFRaG3nKWegyQ.jpeg" /><figcaption>Indexing Types</figcaption></figure><p>However they have some tradeoffs⚖️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*eBdrsmPO8LMRRADcIiSpKw.png" /><figcaption>Pros &amp; Cons of indexing</figcaption></figure><h3>Joins</h3><p>Used to <strong>combine rows</strong> from two or more tables, based on a related column between them.</p><h4>INNER JOIN</h4><p>Rows with matching keys in both tables</p><pre>/*Match product with their categories*/<br><br>SELECT p.id, p.name,c.name<br>FROM products p<br>INNER JOIN Categories c ON p.categoryId = c.id<br></pre><h4>LEFT JOIN</h4><p>All rows from the left table + matches from the right table</p><pre>/*Show all users and any orders they might have*/<br><br>SELECT u.name, o.id<br>from users u<br>LEFT JOIN orders o ON u.id = o.customerID </pre><h4>RIGHT JOIN</h4><p>All rows from the right table + matches from the left table</p><pre>/*Show all users and any orders they might have*/<br><br>SELECT u.name, o.id<br>from orders o<br>RIGHT JOIN users u ON u.id = o.customerID<br><br>/*same example as the above but notice the difference between the order<br>of the tables*/</pre><h4>FULL OUTER JOIN</h4><p>All rows from both tables, matched whenever possible</p><pre>/*Show all users and all orders*/<br><br>SELECT u.name, o.id<br>from orders o<br>FULL OUTER JOIN users u ON u.id = o.customerID<br></pre><h3>Normalization</h3><p>A technique used in database design to <strong>reduce redundancy</strong> and <strong>improve data integrity</strong> by organizing data into tables and ensuring proper relationships.</p><h4>First Normal Form (1NF)</h4><p>Eliminating Duplicate Records:</p><ul><li>All <strong>columns</strong> contain <strong>atomic values</strong> (smallest possible units of data).</li><li>Each <strong>row</strong> is unique (i.e., no duplicate rows).</li><li>Each column has a <strong>unique name</strong>.</li><li>The order in which data is stored does not matter.</li></ul><blockquote><strong><em>Example</em></strong><em>:</em> If a column stores multiple “Phone numbers” for the same user this violates 1NF, we need to separate phone numbers to separate rows</blockquote><h4>Second Normal Form (2NF)</h4><p>Eliminating Partial Dependency:</p><ul><li>Must satisfy 1NF conditions</li><li>Each non-key attribute must depend entirely on the primary key, not a part of it</li></ul><blockquote><strong><em>Example</em></strong><em>:</em> If (<strong>StudentId, CourseId</strong>) is a composite key, and <strong>StudentName </strong>depends only on <strong>StudentId</strong>, this violates 2NF. We have to move <strong>StudentName</strong> into a separate table where it depends only on <strong>StudentId</strong>.</blockquote><h4>Third Normal Form (3NF)</h4><p>Eliminating Transitive Dependency:</p><ul><li>Must satisfy 2NF conditions</li><li>Non-prime attributes should not depend on other non-prime attributes</li></ul><blockquote><strong><em>Example</em></strong><em>:</em> Consider a table with <strong>(StudentID, CourseID, Instructor)</strong>. If <strong>Instructor</strong> depends on <strong>CourseID</strong>, and <strong>CourseID</strong> depends on <strong>StudentID</strong>, then <strong>Instructor</strong> indirectly depends on <strong>StudentID</strong>, which violates 3NF. To resolve this, place <strong>Instructor</strong> in a separate table linked by <strong>CourseID</strong>.</blockquote><p>There are also <strong>Boyce-codd normal form (BCNF)</strong>,<strong> Fourth normal form (4NF)</strong>, and <strong>Fifth normal form(5NF)</strong> but we’re not going to talk about them in this guide.</p><h3>Relationships</h3><p>Define how tables are connected to one another.</p><h4>One-to-One</h4><p>Each record in table A is associated with one, and only one, record in table B and vice versa.</p><pre>/* Each user has one passport */<br><br>CREATE TABLE Users{<br>id INT PRIMARY KEY,<br>username VARCHAR(32),<br>....<br>}<br>CREATE TABLE Passports{<br>id INT PRIMARY KEY,<br>user_id INT UNIQUE,<br>....<br>FOREIGN KEY (user_id) REFERENCES users(id);<br><br>/* here we can include the foreign key in either of the tables */<br></pre><h4>One-to-Many</h4><p>Each record in table A can be associated with one or more records in table B, but every record in table B is associated to only one record in table A.</p><pre>/* Each user can have multiple orders*/<br><br>CREATE TABLE Users{<br>id INT PRIMARY KEY,<br>username VARCHAR(32),<br>....<br>}<br>CREATE TABLE Orders{<br>id INT PRIMARY KEY,<br>user_id INT UNIQUE,<br>....<br>FOREIGN KEY (user_id) REFERENCES users(id);<br><br>/* here we have to add the foreign key in the &quot;many&quot; side */</pre><h4>Many-to-One</h4><p>Multiple records in table B can be associated with one record in table A.</p><pre>Other side of the one-to-many relationship</pre><h4>Many-to-Many</h4><p>Each record in table A can be associated with one or more records in table B, and vice versa.</p><pre>/* Each student can enroll in multiple courses, and each course can<br> have multiple students*/<br><br>CREATE TABLE Students{<br>  student_id INT PRIMARY KEY,<br>  student_name VARCHAR(32),<br>  ....<br>}<br>CREATE TABLE Courses{<br>  course_id INT PRIMARY KEY,<br>  course_name VARCHAR(255) UNIQUE,<br>  ....<br>}<br>CREATE TABLE Student_Courses{<br>  student_id INT,<br>  course_id INT,<br>  PRIMARY KEY(student_id, course_id),<br>  FOREIGN KEY (student_id) REFERENCES Students(student_id),<br>  FOREIGN KEY (course_id) REFERENCES Courses(course_id)<br>}<br><br>/* since it&#39;s a many-to-many relationship, we need to create a <br>different table for the mapping*/</pre><h4>Self-referencing</h4><p>A table has a foreign key that references its primary key.</p><pre>/* If we have a site hierarchy, where a site can be the parent of another<br> site, parent_id can reference site_id in the same table.*/<br><br>CREATE TABLE Sites{<br>  site_id INT PRIMARY KEY,<br>  site_name VARCHAR(32) UNIQUE,<br>  parent_id INT,<br>  ....<br>  FOREIGN KEY (parent_id) REFERENCES Sites(site_id)<br>}<br></pre><h4>Aggregation Functions</h4><p>Functions that are used within the sql query, to perform a set of calculations on the retrieved rows and return a single value. They’re usually used with <strong>GROUP BY</strong> clause. All aggregate functions ignore <strong>NULL</strong> values, except COUNT(*) which includes them.</p><h4>MIN()</h4><p>Returns the min value of the selected column</p><pre>SELECT min(age)<br>FROM students<br><br>/* or with GROUP BY */<br><br>SELECT min (age), courses_count<br>FROM students<br>GROUP BY courses_count</pre><h4>MAX()</h4><p>Returns the max value of the selected column</p><pre>SELECT max(age)<br>FROM students<br><br>/* or with GROUP BY */<br><br>SELECT max (age), courses_count<br>FROM students<br>GROUP BY courses_count</pre><h4>COUNT()</h4><p>Returns the count of rows that matches a specified criteria</p><pre>SELECT Count(*)<br>FROM students<br><br>/* or we could specify a condition */<br><br>SELECT count(student_id)<br>FROM students<br>WHERE age &gt; 20;<br><br>/* or with GROUP BY */<br><br>SELECT COUNT(*) AS [Number of records], age<br>FROM students<br>GROUP BY age;</pre><blockquote>COUNT(*) → counts all rows even thos with null values<br>Count(name) → if <em>name </em>column has null values, it will not count these rows.</blockquote><h4>SUM()</h4><p>Returns the total sum of a numeric column</p><pre>SELECT SUM(courses_count)<br>FROM students<br><br>/* or we could specify a condition */<br><br>SELECT SUM(courses_count) AS totalCourses /* we can give it an alias */<br>FROM students<br>WHERE age &gt; 20;<br><br>/* or with GROUP BY */<br><br>SELECT SUM(courses_count) AS totalCourses, age<br>FROM students<br>GROUP BY age;</pre><h4>AVG()</h4><p>Returns the average of a numeric column</p><pre>SELECT AVG(courses_count)<br>FROM students<br><br>/* or we could specify a condition */<br><br>SELECT AVG(courses_count)<br>FROM students<br>WHERE age &gt; 20;<br><br>/* or with GROUP BY */<br><br>SELECT AVG(course_count), age<br>FROM students<br>GROUP BY age;</pre><h3>Order of SQL query execution</h3><p>SQL queries aren’t executed in the order you write them — instead, the database follows a specific logical order:</p><ol><li>FROM → Identify source tables and apply joins</li><li>WHERE → Filter rows before grouping</li><li>GROUP BY → Group rows for aggregation</li><li>HAVING → Filter aggregated groups</li><li>SELECT → Select and compute the final columns</li><li>DISTINCT → Remove duplicate rows</li><li>ORDER BY → Sort result set</li><li>LIMIT / OFFSET → Return a subset of the rows</li></ol><pre>SELECT department, COUNT(*) as employee_count <br>FROM employees<br>WHERE status = &#39;active&#39;<br>GROUP BY department<br>HAVING COUNT(*) &gt; 5<br>ORDER BY employee_count DESC<br>LIMIT 10;<br><br>/* <br>   1. FROM -&gt; retrieves rows from employee table<br>   2. WHERE -&gt; filters rows where status = &#39;active&#39;<br>   3. GROUP BY -&gt; groups filtered rows by department<br>   4. HAVING -&gt; filters groups where count of rows is greater than 5<br>   5. SELECT -&gt; selects desired columns (department) and applies aggregated<br>      function (COUNT(*) AS employee_count)<br>   6. ORDER BY -&gt; sort the result by employee_count descendingly<br>   7. LIMIT -&gt; return only the top 10 rows<br>*/<br>   <br></pre><h3>Query optimization</h3><ol><li>Avoid SELECT * → fetch only required columns</li><li>Use proper indexes → especially on WHERE, JOIN, ORDER BY, and GROUP BY , but avoid indexing columns with little distinct values</li><li>Apply filters as early as possible to reduce number of scanned rows</li><li>Avoid functions on indexed columns</li></ol><pre>-- created_at is indexed, but function blocks index<br>-- ❌ Not SARGable (index won&#39;t be used):<br>SELECT * FROM orders<br>WHERE DATE(created_at) = &#39;2024-04-01&#39;;<br><br>-- Uses index on created_at<br>-- ✅ index-friendly:<br>SELECT * FROM orders<br>WHERE created_at BETWEEN &#39;2024-04-01&#39; AND &#39;2024-04-01 23:59:59&#39;;</pre><p>5. Use <strong>EXISTS</strong> instead of <strong>IN</strong> for subqueries</p><p>6. Use <strong>joins </strong>instead of subqueries</p><p>7. Use <strong>LIMIT</strong> with <strong>ORDER BY</strong> for paginated results</p><p>8. Prefer <strong>UNION ALL </strong>over <strong>UNION</strong></p><p>9. Avoid <strong>DISTINCT</strong> unless necessary</p><p>10. <strong>Use EXPLAIN / ANALYZE</strong> to inspect execution plans</p><ul><li>EXPLAIN shows how the SQL engine plans to execute your query: indexes used, join algorithms, row estimates, etc.</li><li>Helps identify slow parts and optimize accordingly.</li></ul><h3>🎯 Interview Prep Questions</h3><ul><li>What is normalization? Give examples of 1NF, 2NF, 3NF.</li><li>How does indexing affect performance?</li><li>Difference between DELETE, DROP, and TRUNCATE</li><li>Difference between join types</li><li>Design a schema for a social media app.</li><li>Explain ACID properties.</li><li>How would you optimize a slow query?</li><li>Order of query execution</li></ul><p>💡 <strong>Tip:</strong> Want to practice SQL right away? try this online sql editor</p><p><a href="https://sqliteonline.com/">SQL Online IDE - Fast SQL Editor | SQL Compiler</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ec12829dd53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kafka 101]]></title>
            <link>https://medium.com/@lamaelmalatawy/kafka-101-f669936ce888?source=rss-a6bbe0eec3d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f669936ce888</guid>
            <category><![CDATA[kafka-producer]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[kafka-consumer]]></category>
            <dc:creator><![CDATA[Lamaelmalatawy]]></dc:creator>
            <pubDate>Sat, 08 Mar 2025 18:21:57 GMT</pubDate>
            <atom:updated>2025-05-12T08:26:42.352Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Fundamentals you need to know about Kafka…</em></p><blockquote>In this blog we’re going to talk about what is Kafka, its architecture, when to use it, and when NOT to use it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6sdV3G4Xgl89aIJjk0XBRA.png" /></figure><h3><strong>So what is Kafka?</strong></h3><p>Kafka is an open-source event streaming platform used to collect, store, and process real-time data streams at scale. It was originally developed at Linkedin, then adopted as an open-source project under the Apache Software Foundation</p><p><strong>Common use cases include:</strong></p><ul><li>Pub-Sub messaging</li><li>Event sourcing</li><li>Website activity tracking</li><li>Stream processing</li></ul><p>It’s a good fit for <strong>large scale message processing</strong> applications since it is more robust, reliable, and fault-tolerant compared to traditional message queues.</p><h3><strong>As an overview</strong></h3><p>kafka accepts a stream of <strong>events </strong>written by data <strong>producers </strong>and stores them in <strong>partitions </strong>distributed across <strong>brokers</strong>(servers). A group of brokers form a <strong>cluster</strong>.<strong> Events </strong>are structured as a key-value pair which are grouped into <strong>topics </strong>and read by <strong>consumers </strong>subscribing to those topics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*ltlRxODe9qY24Ld-s2ZZIg.png" /><figcaption>Kafka’s architecture</figcaption></figure><p>Lets now take a deeper dive into each of those core principles:</p><h3><strong>Events</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/1*tjPy89xfoBwoohLSXO5kcw.png" /></figure><p>An event is something that has happened. It’s a combination of notification (when) and state (what). They are immutable, once an event is produced, it cannot be undone. It has the data model of <strong>key-value pair.</strong></p><p>Kafka is loosely typed, so internally events are just a sequences of bytes. However, your programming language is probably not loosely typed, so the process of going back and forth between the way the<strong> key-value pair</strong> is represented in your programming language and kafka is called <strong>serialization </strong>and <strong>deserialization.</strong></p><h3><strong>Topics/Logs:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*GQ68TsD-P3dHxudFGwcW4w.png" /></figure><p>Topics are named containers for similar events.</p><ul><li>Immutable and work in a FIFO order.</li><li>One system can contain multiple topics.</li><li>Cannot be indexed, we can only seek by an offset.</li></ul><p>Topics are durable, events can be stored in them forever, however retention rate is configurable where you can set a certain time for events to expire or even when a topic reaches a certain size. The reason why topics are so durable is that logs that underlie topics are just files stored on a disk.</p><h3><strong>Partitioning</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*17UG5RZtgisg-mz4zOoBfw.png" /></figure><p>Topics can be partitioned. Partitioning takes a single log and breaks it into multiple logs, each can be on a separate node inside a kafka cluster. <strong>This’s what makes kafka scalable</strong>.</p><p><strong>How to decide which partition in a topic to write to?</strong></p><ul><li>If the key of the event is <strong>null</strong>, messages are distributed <strong>sequentially </strong>through each partition.</li><li>If the key is <strong>not null</strong>, then its used to determine this message goes to which partition</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*1AQwAathbJKsAoLcdaAGiw.png" /><figcaption>How the key of an event determines which partition the event goes to</figcaption></figure><p>This ensures that messages with the same key always go to the same partition and are saved in order, while you can’t maintain the order of messages that have null keys as they’re distributed among partitions.</p><h3>Cluster</h3><p>A <strong>network of brokers/nodes</strong> working together to move data for processing, maintaining speed, durability, and scalability.</p><h3><strong>Brokers</strong></h3><p>A broker is a computer, instance, or a container running kafka process.</p><ul><li>Manages partitions.</li><li>Handles write and read requests.</li><li>Manages replication of partitions.</li></ul><h3>Replication</h3><p>Since brokers are at risk of failing, we need to copy partition data to other brokers as backup. Those copies are called <strong>follower replicas.</strong></p><ul><li><strong>One lead</strong> replica and <strong>N-1 </strong>followers.</li><li>Writes and reads happen to the leader, and then the leader and followers work together to copy data among each other.</li><li>Configurable in the producer.</li></ul><h3>Producers</h3><p>Client applications that <strong>create </strong>data, and are constantly writing events to kafka topics</p><ul><li>Decide which partition to write to according to the key of the event</li><li>Decide the number of brokers who need to acknowledge receiving the message before it is considered a successful write</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kk9Cnds7R4iYNw-BcC9JAg.png" /></figure><h3>Consumers</h3><p>Client applications that <strong>read</strong> messages from Kafka topics.</p><ul><li>Consumers need to only specify which <strong>topic </strong>to listen to and one <strong>broker </strong>to connect to. Connecting to one broker automatically connects the consumer to <strong>the whole cluster</strong> so kafka will take care of figuring out the right broker to read from.</li><li>Data is read<strong> in order for each partition</strong>, but in parallel across partitions so we have no way of knowing which partition is going to be read first and this is why there is <strong>no ordering across partitions in kafka</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PeqcjHHCoo8ugFVfIK0Nxw.png" /></figure><h4><strong>Consumer Groups:</strong></h4><p>Consumers read data in consumer groups.</p><ul><li>Partitions are <strong>exclusive</strong> to one consumer in a group.</li><li>The first consumer manages the distribution of partitions among consumers in the group.</li><li>We can scale horizontally by simply adding more consumers to the group, however, if the number of consumers is more than the number of partitions, those extra consumers will remain idle.</li></ul><p>If we want multiple consumers to read from the same topic, to process data in different ways for example, those consumers must be in<strong> different consumer groups.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*Ai_9dhE1kTcKFaJ8PmDfPg.png" /></figure><h4><strong>Offset:</strong></h4><p>Kafka stores the offsets at which a consumer has been reading from in a topic named “__consumer_offsets”.</p><h4>What happens when a consumer dies?</h4><p>Each consumer sends “heartbeat requests” to the broker at a set interval. If a consumer does not respond in time, a rebalance is triggered. The broker’s record of the associated <strong>offset</strong> determines where the consumer will begin reading after a rejoin. As long as the <strong>Group ID</strong> remains the same, it can pick up exactly where it left off, <strong>without any risk of data loss (fault tolerance).</strong></p><h3>What makes kafka so fast?</h3><p>Each topic is split into partitions, and each partition can live on a different broker in a cluster. When data is written into a partition, its quickly and simply appended to the end of this partition, no redistribution is required so no time is consumed.</p><h3>What makes kafka so scalable?</h3><p>Partitions are key to kafka scalability as they allow the topic to scale beyond a size that will fit on a single server, and messages to be processed in parallel across multiple consumers to achieve high throughput.</p><h3>What makes kafka so durable?</h3><p>Since each leader partition copies data to N-1 follower partitions across the cluster, when a node fails, whether its a leader or a replica, its backed up.</p><h3>What makes kafka so powerful?</h3><ul><li>Handles multiple producers sending data simultaneously without performance degradation</li><li>Handles multiple consumers efficiently by allowing multiple consumer groups to read from the same topics independently</li><li>Tracks what’s been consumed using consumer offset stored within kafka itself, which ensures that consumers can continue exactly where they left off in case of failure</li><li>Provides disk space retention policies which allow us to store messages after the were consumed based on time or size limits we define, so nothing is lost unless we decide to clear it.</li></ul><p>Apache Kafka is an incredibly powerful and versatile event streaming platform, designed to handle large-scale, real-time data processing with high throughput, low latency, and fault tolerance. Its distributed architecture, scalability, and durability make it an ideal choice for use cases like website activity tracking, and stream processing. <strong>However</strong>, Kafka is not a one-size-fits-all solution.</p><h3>When NOT to use Kafka</h3><ul><li><strong>Simple or low-volume data processing:</strong> If your data processing needs are simple or your data volume is low, using Kafka might be overkill. Simpler tools or traditional messaging systems, such as RabbitMQ, could be more appropriate and easier to manage.</li><li><strong>Limited resources:</strong> Running and managing Kafka clusters require significant resources in terms of hardware, infrastructure, and operational expertise. If you have limited resources or budget constraints, Kafka might not be the most cost-effective option.</li><li><strong>Real-time analytics with complex processing:</strong> It’s best to avoid using Kafka as the processing engine for ETL jobs, especially where real-time processing is needed. However, there are third-party tools you can use that work with Kafka to give you additional robust capabilities.</li><li><strong>Small-scale deployments:</strong> Setting up and maintaining Kafka clusters can be complex, especially for small-scale deployments. However, you can choose simple alternatives if scalability is not the issue.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f669936ce888" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>