<?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 Dilmi Siriwardhana on Medium]]></title>
        <description><![CDATA[Stories by Dilmi Siriwardhana on Medium]]></description>
        <link>https://medium.com/@dthrishala.siriwardhana?source=rss-4cbd6866bab4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rK4FnWYrpnV3FAwhQVAqMw.png</url>
            <title>Stories by Dilmi Siriwardhana on Medium</title>
            <link>https://medium.com/@dthrishala.siriwardhana?source=rss-4cbd6866bab4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 03:14:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dthrishala.siriwardhana/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[SAGA Design Pattern]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/saga-design-pattern-8c744c53f3da?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c744c53f3da</guid>
            <category><![CDATA[saga-pattern]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Mon, 05 May 2025 18:24:55 GMT</pubDate>
            <atom:updated>2025-05-05T18:24:55.131Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ReAsA0YZkG1Wkl1lXmHO5Q.jpeg" /></figure><p>The Saga design pattern manages data consistency across microservices in distributed transactions. A saga breaks down a large transaction into smaller, local transactions, each updating a service and triggering the next step via messages or events. If a step fails, compensating transactions are executed to reverse the changes.</p><p>Use the Saga pattern when you need to:</p><ul><li>Ensure data consistency in distributed system without tight coupling.</li><li>Rolling back or compensate failed steps within a transaction flow.</li></ul><p>Avoid using Saga for:</p><ul><li>Tightly coupled transactions.</li><li>Complex compensations affecting earlier transactions.</li><li>Cyclic dependencies between services.</li></ul><p>SAGA can be implement in 2 ways:<br>1. Choreography (event base)<br>2. Orchestration (command base)</p><h3>1. Choreography</h3><p>Imagine a ballet where each dancers knows their steps and interacts without a conductor. Similarly, services interact through events published to a message broker (Ex: Kafka). Each service listen for events, performs its work, and email the next event.</p><p>Ex: Customer-onboarding involves microservices for Registration, Credit check, Address validation, and Criminal check. Each step publishes an event to Kafka ,triggering the next service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*qdVPXtlmplSKrU3kQv7YrA.png" /></figure><h4>When to use:</h4><ul><li>For simple workflows with minimal dependencies.</li><li>When services can independently react to events.</li></ul><h3>2. Orchestration</h3><p>Picture an orchestra with a conductor managing each instrument’s timing. Here, a central coordinator manages the entire transaction flow by sending commands to services and handling response.</p><p>Ex: An order management process involves checkout, payment, inventory and shipment services. An order service orchestrates the process, ensuring each step occurs in sequence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cqvwAB43CZQ1mt-7S26QvA.png" /></figure><h4>When to use:</h4><ul><li>For complex workflows with many dependencies.</li><li>When a central controller is required to handle failures and rules.</li></ul><h3>Choreography VS Orchestration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*A6H-xfFgNLAl6z5r5oSI2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*7MyZyu67BLMXldkmZvQkQA.png" /></figure><h3>References</h3><ul><li><a href="https://camunda.com/blog/2023/02/orchestration-vs-choreography/">Orchestration vs Choreography</a></li><li><a href="https://learn.microsoft.com/en-us/azure/architecture/reference-architectures/saga/saga">Saga pattern - Azure Design Patterns</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c744c53f3da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Change Data Capture]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/change-data-capture-93e2f70754e5?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/93e2f70754e5</guid>
            <category><![CDATA[change-data-capture]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Mon, 05 May 2025 18:23:57 GMT</pubDate>
            <atom:updated>2025-05-05T18:23:57.712Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q7ch1RviGShSWAfvYcoNKQ.jpeg" /></figure><h3>Common issues impacting system reliability</h3><p><strong>&gt; System performance problems</strong></p><ul><li>The system is slow time to time.</li><li>Processing large files causes slowdowns.</li><li>Batch job configured in the system impact other processes.</li></ul><p><strong>&gt; Unreliable audit trials</strong></p><p><strong>&gt; Transition to an event-driven design is risky</strong></p><ul><li>Ex: You save a customer purchase order, and an event is emitted. If your system crashes during the event emitting, emitting the event part is fail.</li></ul><h4>Using CDC to address these issues</h4><p>CDC is a method used to track and record changes made to data in databases. By designing the architecture solution around CDC, many of challenges can be solved.</p><h3>Importance of CDC</h3><p>&gt; <strong>Event-driven notifications</strong></p><ul><li>CDC tracks changes at the database level.</li><li>When configured CDC on a table, it emits events to indicate what has happened.</li><li>Ex: A record was inserted, updated or deleted</li></ul><p><strong>&gt; Improved performance through offloading</strong></p><ul><li>Events from the main database can be captured and processed on a replica database.</li><li>Reporting, batch jobs and frequent reads can be executed on the replica without impacting the main database.</li></ul><p><strong>&gt; Sync different type of databases</strong></p><ul><li>Ex: Reports run on a MSSQL database while other systems use MySQL/PostgreSQL/Oracle.</li><li>CDC enables seamless synchronization across databases, allowing for unified data handling.</li></ul><p><strong>&gt; Detailed audit trials</strong></p><ul><li>CDC captures changes at the database level, ensuring events are emitted only when data modifications occur.</li><li>Ex: If a user updates a record, CDC logs details such as the previous and new values.</li></ul><p><strong>&gt; Sync with external systems</strong></p><ul><li>CDC can transform database changes into files (Ex: XML,JSON or PAR) and store them in S3 buckets or other storage solutions. (NAS, local storage,…)</li><li>This facilitate seamless integration with third party systems.</li></ul><p><strong>&gt; Data archival</strong></p><ul><li>CDC can send data to archival storage, enabling safe deletion from the main database while ensuring availability for reporting.</li><li>But your have to make sure your reports are seamlessly read from archival data sources to avoid the need for separate reporting systems for both live and archival data sources.</li></ul><p><strong>&gt; Separation of concerns</strong></p><ul><li>CDC supports CQRS (Command Queries Responsibility Segregation) design pattern, where one database handles writes, and another handles reads.</li><li>Synchronization between databases occurs within milliseconds, ensuring near real time updates.</li></ul><h3>Implementing CDC Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*ySMiCKAJRBggwhHudrQaug.png" /></figure><ul><li>Enable CDC on the source database.</li><li>Configure CDC to emit events for changes.</li><li>Use Debezium source connector to read the CDC event and publish them to Kafka.</li><li>Events can go in formats like AVRO (compressed and schema driven) or JSON.</li><li>Use JDBC connectors to sync data with another database (Ex: MSSQL).</li><li>Deploy an audit service to listen to Kafka events and generate audit records.</li><li>Dispatch services process events only when actual changes occur.</li><li>Ex: For updates, CDC captures both the ‘before’ and ‘after’ versions; for deletes, only the before version; for inserts, only the after version.</li><li>If the dispatch service is offline, implement a mechanism to retrieve unprocessed events once the service resumes.</li><li>Decouple event consumers from the source database to avoid performance bottlenecks.</li><li>Events can trigger file generation, archival, and integration tasks.</li><li>CDC avoids stress on the source database by shifting workloads to decoupled services.</li></ul><h3>CDC Implementation Patterns</h3><p>Log based <br>Trigger based<br>Change data publisher-subscriber model <br>Change data mesh</p><h3>Real World Examples for CDC</h3><p>Netflix<br>Uber<br>Airbnb</p><h3>References</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FIXOgKcwfER8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIXOgKcwfER8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FIXOgKcwfER8%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/af658e6441e3d841af096c6419948602/href">https://medium.com/media/af658e6441e3d841af096c6419948602/href</a></iframe><p><a href="https://www.geeksforgeeks.org/change-data-capture-cdc/">Change Data Capture (CDC) - GeeksforGeeks</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93e2f70754e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kafka]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/kafka-6829bbab54ab?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6829bbab54ab</guid>
            <category><![CDATA[zookeeper-in-kafka]]></category>
            <category><![CDATA[kafka-consumer]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Mon, 05 May 2025 18:23:01 GMT</pubDate>
            <atom:updated>2025-05-05T18:23:01.901Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cf74bZ370iFaQX-S6tkurA.jpeg" /></figure><p>Kafka is an event streaming platform.</p><h4>Event Streaming</h4><ul><li>The process of continuously capturing, storing, and processing event data in real-time.</li><li>Conceptually event has a key, value and a timestamp.</li><li>Event stream: a sequence of events</li><li>Events are serialized when written to a topic and deserialized when read.</li></ul><p>For more information, visit: <br><a href="https://kafka.apache.org/intro"><em>Apache Kafka: A Distributed Streaming Platform</em></a></p><h4>Why do we need a messaging system?</h4><p>Rest APIs are asynchronous (we don’t wait until things happen).<br>However, when microservices use HTTP 1.1, they become synchronous.</p><p>To avoid this limitation, the solution is to use a messaging system like Kafka or RabbitMQ.</p><p>Messaging systems decouple producers and consumers, enabling asynchronous communication.</p><p><strong>Kafka act as:</strong></p><ul><li>Producer</li><li>Consumer</li><li>Stream Processor</li><li>Connector</li></ul><h3>Kafka Terminologies</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*qTl3-xCsQjnwUErJeW0DEA.png" /></figure><p><strong>Kafka Producers </strong><br>Applications that write messages to brokers by serializing them.</p><p><strong>Kafka Consumers </strong><br>Applications that read messages from brokers by deserializing them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*nk4bCNOS3yNtScXYMlgzuA.png" /></figure><p><strong>Kafka Topic<br></strong>A category to which records are sent by producers and from which records are retrieved by consumers.</p><p><strong>Kafka partition</strong><br>A topic is split into partitions for parallelism and scalability.</p><p><strong>Kafka Broker </strong><br>A machine that stores and serves Kafka messages.</p><p><strong>Kafka Cluster</strong> <br>A group of Kafka brokers, along with Zookeeper and other services.</p><p><strong>Zookeeper </strong><br>A program that manage the Kafka cluster, handling tasks like load balancing and replica lag monitoring. In the latest Kafka versions, Zookeeper is optional.</p><p><strong>Group Coordinator</strong>:</p><ol><li>It’s one of the elected brokers in the cluster from Kafka server side.</li><li>Consumers interact with the Group Coordinator for offset commits and fetch requests.</li><li>Consumer sends periodic heartbeats to Group Coordinator.</li></ol><h3>Kafka consumer groups and partition balancing</h3><p>Always, <br><strong>number of consumers in a consumer group ≤ number of partitions</strong></p><p>Whenever you add a consumer to the consumer group, Kafka automatically balancing it based on the number of partitions you have. This is called ‘rebalancing’.</p><p>You need to specify the number of partitions while creating the topic. New partitions won’t be create automatically.</p><p>As soon as you increase number of partitions, producer and consumer will be notified of new partitions, and leading them to rebalance. Once rebalanced, producer and consumer will start producing and consuming from the new partition.</p><p>Let’s see some examples to understand the rebalancing process of Kafka.</p><p><strong>Ex 1:</strong> The consumer group has only 1 consumer. So he consumes data from all partitions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HtzhU2CLflf92VRkFHSg6A.jpeg" /></figure><p><strong>Ex 2:</strong> There are 2 consumers in the consumer group and 3 partitions. We divide these partitions equally among the consumers. So 1 consumer must get at least 1 partition. But 1 partition is remaining. So we can give it to one of these 2 consumers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TvM9n6tzbfYoC9EPyFokJQ.jpeg" /></figure><p><strong>Ex 3:</strong> There are 3 consumers and 3 partitions, So we can equally distributed these 3 partitions among the 3 consumers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NNvNqp6DqdUia92RGsMK8w.jpeg" /></figure><p><strong>Ex 4:</strong> There are 4 consumers and 3 partitions. So 3 consumers can have partitions. But 1 consumer is remaining and he does not have a partition to consume data. So that consumer is in idle state. Kafka doesn’t send messages to C4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2fO-3HeO2eHHCmNxOWfcA.jpeg" /></figure><p>&gt; So what is the advantage of having a consumer 4 in idle state? <br>If one of the 3 consumers got crashed, as an example we think C3 crashed, there is one consumer already running in idle state. So then Kafka can immediately hand over the rest of the things to the next consumer (C4).</p><p>If we kill a consumer, it will take little time based on the zookeeper heartbeat configuration. After little while this will rebalancing.</p><p>For more information about zookeeper, visit:<br><a href="https://cwiki.apache.org/confluence/display/ZOOKEEPER/Index">https://cwiki.apache.org/confluence/display/ZOOKEEPER/Index</a></p><p><strong>Ex 5:</strong> There can be multiple consumer groups and each consumer group can consume from a partition only once. There can be ungrouped consumers that consume from all the partitions.</p><p>We want consumer groups because a service may have multiple instances. This ensures that all consumers within a consumer group do not receive the same message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cpxYibsiHZ_zvRn001so1A.jpeg" /></figure><h3>How to produce a message to Kafka</h3><p>To determine the partition for a message, the following formula is used:</p><p>i=key_hash % number_of_partitions</p><p>This calculates the partition i where the message will be stored</p><ul><li>Each group consumes all messages from a topic independently.</li><li>A group can consist of one or more consumers, depending on your requirements.</li></ul><p>Kafka guarantees the order of messages within a partition, <br>but there is no such guarantee across a topic (between partitions).</p><p>If you provide a key with the producer, then Kafka uses the modulo algorithm to determine the partition based on the key.</p><p>If you always provide the same key, Kafka guarantees that the messages with that key will go to the same partition and will eventually be consumed by the same consumer. (unless that consumer is terminated)</p><p>But if no key is provided, Kafka distributed the messages using a random round robin approach.</p><p>This can lead to scenarios where messages from the same customer are sent to different partitions:<br>The 1st message goes to one partition.<br>The 2nd message goes to another partition.<br>The 3rd message goes to yet another partition.</p><h3>Kafka Offsets</h3><h4>&gt; Partition Offset</h4><p>Refers to the last offset of a partition</p><p>When Kafka’s retention period expires, some messages are removed. As a result, the first and last offsets in the partition change over time.</p><p>Messages in a partition are stored in binary format, typically as an array of bytes.</p><p><strong>Retention period</strong></p><p>The duration for which Kafka retains messages in the broker.<br>Default: 7 days<br>Can be adjusted to an unlimited retention period if required.<br>Kafka’s retention policy ensures that messages are not deleted after being delivered; they are retained for future use.</p><h4>&gt; Consumer Offset</h4><p>Refers to the last message consumed message consumed by a consumer.</p><p>This enables a consumer to resume processing from where it left off if the stream application is stopped or encounters an unexpected failure.</p><p>The consumer offset is stored in a Kafka topic called <em>_consumer_offsets. </em>Each partition in the <em>_consumer_offsets </em>topic correspond to a partition in the source topic.</p><p>When managing consumer offsets manually:<br>You should be ready to get the messages again and again in the same batch.<br>But when you disable retry it will start the same message and your lag will grow.</p><p>Ex :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*pCZvTFg9oJdiQKq8GbP9pg.png" /></figure><p>partition offsets : <br>partition 0 = 12<br>partition 1 = 8<br>partition 2 = 10<br>partition 3 = 11</p><p>consumer offsets : <br>partition 0 = 6<br>partition 1 = 5<br>partition 2 = 7<br>partition 3 = 10</p><p><strong>Consumer Lag<br></strong>Consumer Lag is the difference between the last offset stored by the broker and the last offset committed by the consumer for a partition. It indicates how much lag exists between Kafka producers and consumers.</p><p>If the consumer lag is too large— they’d be nearly useless. This consumer lag tells us how far behind each consumer (Group) is in each partition. Smaller lag ensures the more real-time data processing.</p><p>For more information, visit:<br><a href="https://sematext.com/blog/kafka-consumer-lag-offsets-monitoring/"><em>Apache Kafka Consumer Lag Monitoring: How to Check and Fix It to Stream Data Smoothly</em></a></p><p><strong>Replica Lag<br></strong>Replica Lag is the difference between the last offset written to the leader replica and the last offset received by the follower replica(s).<br>In a Kafka cluster, data is distributed across multiple brokers, and each partition of a topic has a leader replica and one or more follower replicas.</p><p>Leader Replica : The primary source for responsible for handling reads and writes.<br>Follower Replicas : Replicate data from the leader replica to maintain consistency.</p><p>Ex: If the leader has written message up to offset 1000 and the follower has received up to offset 990, the replica lag for that partition is 10.</p><h4>DLQ (Dead Letter Queue)</h4><p>A DLQ is a Kafka topic that used to store messages that cannot be processed successfully.</p><p>Kafka processes messages in batches from source topic. While you can configure the batch size as 1, this is generally not recommended due to poor performance.</p><p>Ex:</p><ul><li>Batch size = 10</li><li>Messages are processed one by one.</li><li>If a single bad message in the batch causes an exception in the application logic, the consumer may crash.</li><li>When the consumer restarts, it will reprocess the same batch (as no commit was made for the batch). This can create a crash loop.</li></ul><p>A DLQ offers a solution by routing problematic messages to another topic for later inspection instead of blocking the entire system.</p><p>Messages in the DLQ needs to be inspected using logs to identify why the failed. These failures are often caused by edge conditions or a bugs in the system. Skipping a message directly from a Kafka topic is difficult, even with admin tools. Using a DLQ is the best practice to handle such cases in production environments.</p><h4>Heartbeat and Session Timeout</h4><p>&gt; Heartbeat Interval (<em>heartbeat.interval.ms)</em></p><ul><li>Specifies how frequency the consumer sends a heartbeat signal to the broker.</li><li>Default: 3000ms (3 seconds)</li></ul><p>&gt; Session Timeout (<em>session.timeout.ms)</em></p><ul><li><em>S</em>pecifies the maximum time within which the broker must receive at least one heartbeat from the consumer.</li><li>If no heartbeat is received within this interval, the broker marks the consumer as dead.</li><li>Default: 10000ms (10 seconds)</li></ul><p>In a network setup under heavy load, it is normal to miss few heartbeat signals. So it is recommended to wait for missing 3 heart beat signals before marking the consumer as dead.</p><p>So we have to set the session timeout greater than the heartbeat interval. but this creates another problem. If the consumer is really dead then rebalancing will not happen until that time interval.</p><p>Or you can configure the session interval as low as it configured and you can call the heartbeat during your process. So you can stay in the cluster without detaching from that because of your long running task.</p><h3>Kafka API</h3><p>There are 5 Kafka API s</p><p>Producer API — publish (write) a stream of events to one/more Kafka topics.</p><p>Consumer API — subscribe (read) to one/more topics and to process the stream of events produced to them.</p><p>Kafka Stream API — to implement stream processing applications and microservices. Input is read from one/more topics in order to generate output to one/more topics.</p><p>Admin API — manage and inspect topics, brokers and other Kafka objects.</p><p>Kafka Connect API — build and reusable data import/export connectors that consume/produce streams of events from and to external systems, so they can integrate with Kafka.</p><h3>Resources</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FwP-FMNuO3D0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DwP-FMNuO3D0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FwP-FMNuO3D0%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/895784006a4183a913a65c496624a4b4/href">https://medium.com/media/895784006a4183a913a65c496624a4b4/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6829bbab54ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DNS with Wireshark]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/dns-with-wireshark-0b329a44245a?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b329a44245a</guid>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[wireshark]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Fri, 31 Jan 2025 06:19:47 GMT</pubDate>
            <atom:updated>2025-01-31T06:19:47.442Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ONpqC_93FA-zweYEJ94XFw.jpeg" /></figure><p>The Domain Name System (DNS) is a system used to store and resolve information about domain names, including IP addresses, mail servers, and other related data.</p><p>For more information, visit: <a href="https://medium.com/@dthrishala.siriwardhana/domain-name-system-and-dns-records-50a8e14c9cec"><em>DNS Part 1</em></a></p><p>DNS typically uses TCP or UDP as its transport protocol, and the well known port for DNS traffic is 53.</p><h3>Clearing DNS Cache and Observing DNS Resolution</h3><p>Before analyzing DNS queries, we need to clear the DNS cache on our computer. This removes any cached DNS entries, ensuring that new requests are resolved through DNS servers on the Internet.</p><pre>ipconfig /flushdns</pre><p>To observe a standard DNS resolution, we can use the following command:</p><pre>nslookup youtube.com</pre><p>This command provides the DNS provider and the IPV4 and IPV6 addresses for the queried domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*pWKbnpWWwar_z__OzaYPSA.png" /></figure><h3>Capturing DNS Traffic with Wireshark</h3><p>Using Wireshark, we can capture DNS requests and responses.</p><p>To filter DNS traffic in Wireshark, use the following display filter:</p><pre>dns</pre><p>Ex1 : I added a column called “DNS Time” to measure response times for DNS queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kycm8WBm4WH2L78BB-OTsg.png" /></figure><p>To view the response corresponding to a specific DNS request, you can apply filters.</p><pre>dns.id == 0x0002</pre><p>The DNS request was appended with a local search domain (BRANDIX.ORG), resulting in a non-existent domain like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ymyu1c8MhILG8yA14TK5pQ.png" /></figure><p>The DNS request was appended with local search domain (BRANDIX.ORG), resulting the non existent domain (youtube.com.BRANDIX.ORG).</p><p>Ex2 : You can observe:</p><ul><li>The client (10.32.32.185) requests the A record and HTTPS record for <em>accounts.youtube.com.</em></li><li>The DNS server (10.227.19.12) responds with a CNAME record pointing to <em>www3.l.google.com</em>.</li><li>It also provides multiple A records (IPV4) for <em>www3.l.google.com</em> and additional information, such as the SOA record.</li><li>The CNAME record simplifies domain management by aliasing <em>accounts.youtube.com</em> to <em>www3.l.google.com.</em></li><li>The A records give the client actual IPs to connect to for <em>accounts.youtube.com</em></li><li>The SOA records specifies the authoritative DNS server for managing the domain.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hnXy_wL6f8102NDzW4Sjg.png" /></figure><h3>References</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqYh6k-S5xC4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqYh6k-S5xC4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqYh6k-S5xC4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d92a62475c29e4856bda7cfd07d3d43/href">https://medium.com/media/7d92a62475c29e4856bda7cfd07d3d43/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b329a44245a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Domain Name System and DNS Records]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/domain-name-system-and-dns-records-50a8e14c9cec?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/50a8e14c9cec</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[dns-records]]></category>
            <category><![CDATA[dns]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Thu, 23 Jan 2025 08:02:45 GMT</pubDate>
            <atom:updated>2025-01-23T08:02:45.228Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*g2Bz2sgGPxiCoEkYzM49Ag.png" /></figure><p>DNS (Domain Name System) resolves domain names to IP addresses. This is because computers don’t understand names, they only understand numbers. So when you type in a domain name such as dilmi.me in a web browser, DNS will resolve that domain name into an IP address so you can retrieve the website.</p><p>In a DNS hierarchy there are 3 main levels of servers. They are root server, top level domain server and the name servers.</p><p>When we type dilmi.me in the browser, computer first checks with local DNS resolver. It has a cache and remembers the IP addresses of websites it visited, so it doesn’t have to ask anyone else if it already has the IP address. If the IP address for dilmi.me is found in the cache, it immediately load the website.</p><p>But if the IP address isn’t in the cache?</p><p>The local DNS resolver has to start a query to find the IP address. So in order to find the correct name server, the query must first go through the top of the DNS hierarchy which is the root server. And once it reaches the root server, the root server will loop at dilmi.me and will directs the resolver to the correct top level domain server.</p><p>The top level domain server is responsible for information of top level domains such as .com, .org, .lk, ...</p><p>The top level domain server will forward the query to the specific name server that’s responsible for the dilmi.me domain. Once the query reaches the name server, dilmi.me will resolved to the IP address so the website can be retrieved.</p><p>The resolver remembers this path and<strong> </strong>stores the IP address in its cache. Next time someone asks for dilmi.me, it will get the IP address from the cache.</p><p>So in a DNS database There are numerous DNS records.</p><h3>DNS RECORDS</h3><h4><strong>*A record</strong></h4><ul><li>Most common DNS record.</li><li>Resolves domain names to IP addresses (IPv4) which is a 32 bit numeric address.</li><li>Ex: when you type dilmi.me in a web browser, the A record is what DNS uses to resolve a domain to an IP address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*AhnqWahsSltUToJr9mtrWw.png" /></figure><p>The “@” symbol in this example indicates that this is a record for the root domain, and the “14400” value is the TTL (time to live), listed in seconds. TTL field tells us how long each record is valid until the next update. The default TTL for A records is 14,400 seconds. This means that if an A record gets updated, it takes 240 minutes (14,400 seconds) to take effect.</p><p>Usage :</p><ul><li>IP address lookups</li><li>Operating a Domain Name System-based Blackhole List (DNSBL). DNSBLs can help mail servers identify and block email messages from known spammer domains.</li></ul><h4><strong>*AAAA record</strong></h4><ul><li>AAAA record resolves domain names to IP addresses (IPv6)</li><li>One of the important differences between IPv6 and IPv4 is that IPv6 addresses are longer than IPv4 addresses. <br>The Internet is running out of IPv4 addresses, just as there are only so many possible phone numbers for a given area code. <br>But IPv6 addresses offer exponentially more permutations and thus far more possible IP addresses.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*XvNmsbDw5P5iEkjnwHebCg.png" /></figure><h4><strong>*CNAME record</strong> (canonical name)</h4><p>Resolve a domain/subdomain name to another domain name. It’s an alias for another domain name. All CNAME records must point to a domain, never to an IP address</p><p>Ex: computers read domain names from right to left and domain names have several parts : a root domain, a top level domain, a second level domain and a subdomain.</p><p>This can also be done by creating an A record.</p><p>Subdomains are also often used when a website has different services running on the same server and are using the same IP address.</p><p>Ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*Hw31Cz3Wz0pooJXcTiO9TA.png" /></figure><p>Pointing a CNAME record to another CNAME record is inefficient because it requires multiple DNS lookups before the domain can be loaded which slows down the user experience, but it is possible. <br>Instead, the CNAME records for both blog.dilmi.me and www.dilmi.me should point directly to dilmi.com.</p><h4><strong>*MX record</strong></h4><p>Directs email to a mail server. Simply points to the server where emails should be delivered for that domain name.</p><p>Ex: when you send an email to dilmi@gmail.com, your MTA/mail transfer agent will query the MX records for gmail.com because it’s looking for an email server.</p><p>DNS will respond back telling the MTA which server to send the email to which, in this case would be mail1.example.com because that’s what the MX record points to. So that’s basically what the MX record does. It tells the world which server to send email to for a particular domain name.</p><p>Ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*4dDcZy1EXGphkXXyMTqBwA.png" /></figure><p>The lower priority value is preferred. The server will always try mailhost1 first because of this. In the result of a message send failure, the server will default to mailhost2.</p><p>The email service could also configure this MX record as same priorities, so that both servers receive an equal amount of mail. This configuration enables the email provider to equally balance the load between the two servers.</p><h4><strong>*SOA (Start Of Authority) record</strong></h4><p>Stores admin information about a DNS zone.</p><p>The DNS zone is a section of a domain name space that a certain administrator has been delegated control over. DNS zones allow a domain namespace such as dilmi.me to be divided into different sections.</p><p>Ex: shop.example.me , blog.example.me , support.example.me</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IipmAxQpkVQCE4M0ghJBXQ.png" /></figure><p>The head administrator could create DNS zones and delegate control over these subdomains to different administrators if he chooses to. So let’s say that the shop and blog subdomain have only a few computers in each domain and the support subdomain has many computers. So since these 2 only have a small amount of computers, the head admin could create one zone for these 2 subdomains and assign an administrator to manage it. But since support has so many computers, the head administrator has created another separate zone just for the support subdomain and then he will assign another administrator to manage it.</p><p>So DNS zones are created for manageability purposes and each will have their own DNS zone file which contains an SOA record.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bV6yv2Ei33DVObiFl2NcdQ.png" /></figure><h4>*NS record</h4><p>Provides the name of the authoritative name server within a domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TQbUT0JFNOXTi9MyjX2O_A.png" /></figure><p>The name server contains all the DNS records necessary for users to find a computer or server on a local network or on the Internet. It is a final authority in a DNS hierarchy. NS record would generally list two name servers; a primary and a secondary</p><p>NS stands for ‘nameserver,’ and the nameserver record indicates which DNS server is authoritative for that domain (i.e. which server contains the actual DNS records). Basically, NS records tell the Internet where to go to find out a domain’s IP address. A domain often has multiple NS records which can indicate primary and secondary nameservers for that domain. Without properly configured NS records, users will be unable to load a website or application.</p><h4><strong>*SRV record</strong> (Service Record)</h4><p>The previous DNS records will point to a server or an IP address. But a SRV record points to a server and a service by including a port number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Qvp8FcdZyvkdw2Tk8CM2A.png" /></figure><p>So when an application needs to find the location of a service on a domain such as voice over IP, instant messaging, or a printer, it will look for a service record to see if there’s a listing for that specific service and it will direct it to the correct server and correct port number.</p><h4><strong>*PTR record</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*mzh96gmAUK4ue3eyOfS-iw.png" /></figure><p>This is the reverse of an A or a AAAA record. <br>A and AAAA records resolve domain names to IP addresses but PTR (pointer) records do the opposite, they resolve IP addresses to domain names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*2sqBhSq3Ud_bL8DiN9-Xww.png" /></figure><p>PTR records are attached to email and are used to prevent email spam. So whenever an email is received, the email server uses the PTR record to make sure that the sender is authentic by matching the domain name in the email with its authentic IP address. This is what’s known as a reverse DNS lookup. But if an email that is sent does not match with its correct and authentic IP address, the email will be flagged as spam.</p><h4>*TXT record</h4><p>Contains miscellaneous information about a domain such as general or conatct information. These are also used to prevent email spam by making sure incoming email is coming from a trusted/authorized source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*O7DDoxxMEXI_4s8N6TQOMg.png" /></figure><p>Lets an admin store text notes in the record. These records are often used for email security.</p><p>The DNS ‘text’ (TXT) record lets a domain administrator enter text into the Domain Name System (DNS). Text is stored in the form of one or more strings within quotation marks. The TXT record was originally intended as a place for human-readable notes. However, now it is also possible to put some machine-readable data into TXT records. One domain can have many TXT records.</p><h4><strong>*HIP record</strong></h4><p>This record uses ‘Host identity protocol’, a way to separate the roles of an IP address; this record is used most often in mobile computing.</p><h3>References</h3><p>CLOUDFLARE | DNS records<br><a href="https://www.cloudflare.com/en-gb/learning/dns/dns-records/">https://www.cloudflare.com/en-gb/learning/dns/dns-records/</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FHnUDtycXSNE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DHnUDtycXSNE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FHnUDtycXSNE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8dd4f16dbc40b056b7f6845dace3213/href">https://medium.com/media/f8dd4f16dbc40b056b7f6845dace3213/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50a8e14c9cec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSL/TLS Protocol]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/ssl-tls-protocol-f840ac22f637?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f840ac22f637</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[tls]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 08:06:42 GMT</pubDate>
            <atom:updated>2024-12-14T13:53:10.898Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to SSL/TLS and Why It Matters</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*x2Qh77BRIAtobTcV_WZooA.png" /></figure><p><strong>Secure Sockets Layer (SSL)</strong> is a communication protocol, that creates a secure connection between two devices on a network. It’s important to establish trust and authenticate the other party before you share data over the internet.</p><p>However, SSL is an older technology that contains some security flaws. <strong>Transport Layer Security (TLS)</strong> is the upgraded version of SSL that fixes existing SSL vulnerabilities. TLS authenticates more efficiently and continues to support encrypted communication channels.</p><h3>Understanding SSL</h3><p>SSL is an encryption-based Internet security protocol. <br>Purpose : ensuring privacy, authentication, and data integrity in internet communications. <br>SSL is the predecessor to the modern TLS encryption used today.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*pQK83zvZpzdDI9Y2UjqtDA.png" /></figure><h4>SSL History</h4><ul><li>SSL 1.0 Netscape — 1994</li><li>S-HTTP (web only)</li><li>SSL 2.0 Netscape (buggy) — 1995</li><li>PCT Microsoft (loser) — 1996</li><li>SSL 3.0 Netscape — 1996</li><li>TLS 1.0 IETF 1999</li><li>TLS 1.1 — 2006</li><li>TLS 1.2 — 2008</li><li>TLS 1.3 — 2018</li></ul><h3>Evolution to TLS</h3><p>There are three main components to what the TLS protocol accomplishes:</p><ul><li>Encryption: hides the data being transferred from third parties.</li><li>Authentication: ensures that the parties exchanging information are who they claim to be.</li><li>Integrity: verifies that the data has not been modified.</li></ul><h4>Key Improvements over SSL</h4><p>TLS was developed as an upgrade to SSL to address several security vulnerabilities. Here are the key improvements TLS introduced over SSL:</p><ul><li><strong>Improved Hash Functions</strong>: TLS uses more secure hashing algorithms (Ex: SHA-256 instead of SSL’s MD5), enhancing data integrity checks.</li><li><strong>Alert Messages</strong>: TLS has a more comprehensive set of alert messages that provide better error reporting and handling mechanisms.</li><li><strong>Efficient Key Exchange</strong>: TLS supports more efficient key exchange mechanisms, such as Diffie-Hellman and Elliptic Curve Diffie-Hellman, which offer forward secrecy.</li></ul><h4>TLS Handshake Overview</h4><p>A TLS connection is initiated using a sequence known as the TLS handshake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LJA8TJAfNY8rHl2xty4dHg.jpeg" /></figure><h4>Key Exchange in TLS</h4><p>-Need secure method to exchange secret key</p><p>-Use public key encryption for this</p><ul><li>‘key-pair’ is used — either one can encrypt and then the other can decrypt.</li><li>slower than conventional cryptography.</li><li>share one key, keep the other private.</li><li>Choices are RSA or Diffie-Hellman</li></ul><h4>Current Usage and Importance</h4><ul><li>Web Browsing (HTTPS)</li><li>Email Security: SMTP, IMAP, and POP3</li><li>Virtual Private Networks (VPNs):</li><li>Instant Messaging and VoIP: Applications like WhatsApp, Signal, and Zoom use TLS to secure instant messaging and calls, protecting against interception and tampering.</li><li>API Security: APIs use TLS to ensure that data exchanged between services remains confidential and unaltered.</li></ul><h3>Comparing SSL and TLS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bXUzj_miu79xIqHwtIxoHA.png" /></figure><h3>Message Authentication in SSL vs TLS</h3><h4>MAC</h4><p>The SSL protocol uses the MD5 algorithm — which is now outdated — for MAC generation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ast65bC9wmCPp9yIMFaBig.jpeg" /></figure><h4>HMAC</h4><p>TLS uses Hash-Based Message Authentication Code (HMAC) for more complex cryptography and security.</p><p>In HMAC, first we check the key length and the block size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*2H1eeVlDGX4yhRvR4ioYZQ.png" /></figure><ul><li>ipad — Inner pad; The constant which equals x36 repeated as many times as block size in bytes (for SHA1 64 bytes).</li><li>opad — Outer pad; The constant which equals x5C repeated as many times as block size in bytes (for SHA1 64 bytes).</li><li><strong>||</strong> — Concatenation of two strings.</li></ul><h3>References</h3><p><a href="https://aws.amazon.com/compare/the-difference-between-ssl-and-tls/">SSL vs TLS - Difference Between Communication Protocols - AWS</a></p><p>What is SSL? | SSL definition<br><a href="https://www.cloudflare.com/en-gb/learning/ssl/what-is-ssl/">https://www.cloudflare.com/en-gb/learning/ssl/what-is-ssl/</a></p><p>What is TLS (Transport Layer Security)?<br><a href="https://www.cloudflare.com/en-gb/learning/ssl/transport-layer-security-tls/">https://www.cloudflare.com/en-gb/learning/ssl/transport-layer-security-tls/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f840ac22f637" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Date and Time: Understanding the Evolution from Legacy APIs to Java 8]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/java-date-and-time-understanding-the-evolution-from-legacy-apis-to-java-8-6b7fcc831374?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b7fcc831374</guid>
            <category><![CDATA[java-date-time]]></category>
            <category><![CDATA[java-8-feature]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 08:05:19 GMT</pubDate>
            <atom:updated>2024-12-06T08:05:19.874Z</atom:updated>
            <content:encoded><![CDATA[<p>Java has a significant improvements in date and time handling, transitioning from older, problematic APIs to the robust, thread-safe ‘java.time’ package introduced in Java 8.</p><h4>Drawbacks of Old Date-Time API (Pre-Java 8)</h4><ul><li>Not thread safe : developers have to deal with concurrency issue while using date</li><li>Poor design : The API was poorly designed.</li><li>Difficult time zone handling : managing time zones was complex and error-prone.</li></ul><h4>Java 8 Date Time API</h4><p>Java 8 introduced a new ‘java.time’ package that resolves these issues by providing a modern, immutable, and thread-safe approach to handling date and time. The package includes several key modules and classes:</p><p>java.time -&gt; the core of the API for representing date and time. It includes classes for date, time and time combined, time zones, instants, duration and clocks.</p><p>java.time.chrono -&gt; generic API for non ISO calendar systems, supporting various calendar types.</p><p>java.time.temporal -&gt; an extended API, allowing interoperations between the date and time classes, querying and adjustments</p><p>java.time.zone -&gt; classes that support time zones, offsets from time zones and time zone rules.</p><h3>Java Legacy (JDK version 7 and below) Date Time Classes</h3><ul><li>System.currentTimeMillis()</li><li>java.util.Date</li><li>java.sql.Date</li><li>java.sql.Time</li><li>java.util.GregorianCalendar</li><li>java.text.SimpleDateFormat</li><li>java.util.TimeZone</li></ul><h4>&gt; currentTimeMillis() Method</h4><ul><li>returns the time since January 1st 1970 in milliseconds. The value returns is a long.</li></ul><pre>public class SystemDemo {<br><br>   public static void main(String[] args) {<br><br>      System.out.print(&quot;Current Time in milliseconds = &quot;);<br>      System.out.println(System.currentTimeMillis());<br>   }<br>} </pre><ul><li>time measurement -&gt; get the time before and after the operation you want to measure, and calculate the time difference.</li></ul><h4>&gt; java.util.Date</h4><ul><li>represent date and time in Java</li><li>inherited by java.sql.Date, java.sql.Time and java.sql.Timestamp interfaces</li></ul><p><strong>Constructors</strong><br>Date() -&gt; initialize the object with the current date and time.<br>Date(long millisec) -&gt; accepts number of milliseconds elapsed since midnight, January 1, 1970.</p><pre>import java.util.Date;<br><br>public class Example {  <br>    public static void main(String[] args) {  <br>        Date date = new Date(); <br>        System.out.println(date);  <br>    }  <br>} </pre><h4>&gt; java.sql.Date</h4><ul><li>extends java.util.Date class</li><li>used in JDBC</li></ul><pre>import java.sql.Date;<br><br>public class Example {  <br>    public static void main(String[] args) {  <br>        long millis=System.currentTimeMillis();  <br>        Date date = new Date(millis);  <br>        System.out.println(date);  <br>    }  <br>} </pre><h4>&gt; java.sql.Time</h4><ul><li>a thin wrapper around the java.util.Date class that allows the JDBC API to identify this as an SQL TIME value.</li><li>java.sql.time(int yy, int mm, int dd);</li><li>java.sql.time(long millisec);</li><li>java.sql.Timestamp represents both date and time formatting including nanosecond details.</li><li>The initial value of time is set to 1st January, 1970. All values of time after that is positive and time before that is negative. *****</li></ul><pre>import java.sql.Time;<br><br>public class Example { <br>    public static void main(String args[]) { <br>        long millis=System.currentTimeMillis();<br>        Time time = new Time(milliS); <br>        System.out.println(time); <br>    } <br>} </pre><h4>&gt; java.util.GregorianCalendar</h4><ul><li>java.util.Calendar class is abstract</li><li>gregorianCalendar is a concrete subclass</li><li>provides the standard calendar system used by most of the world</li><li>GregorianCalendar cal = new GregorianCalendar();</li><li>GregorianCalendar cal = new GregorianCalendar(int year, int month, int date, int hour, int minute, int second);</li></ul><p><strong>Drawbacks</strong></p><ul><li>The MONTH field does not go from 1 to 12. Instead the months run from 0 to 11, where 0 is January and 11 is December.</li><li>The day of week runs from 1 to 7 but Sunday is the first day of the week. 1=sunday, 2=monday, …, 7=saturday.</li></ul><pre>import java.util.GregorianCalendar;<br><br>public class Example {<br>   public static void main(String[] args) {<br>      GregorianCalendar cal = new GregorianCalendar();<br>      System.out.println(&quot;Current Date and Time: &quot; + cal.getTime());<br><br>      // add 2 months <br>      cal.add((GregorianCalendar.MONTH), 2);<br>      System.out.println(&quot;Date after 2 months: &quot; + cal.getTime());<br>   }<br>}<br><br></pre><h4>&gt; java.text.SimpleDateFormat</h4><ul><li>SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner.</li><li>It allows for formatting (date-&gt;text), parsing (text-&gt;date), and normalization.</li><li>SimpleDateFormat allows you to start by choosing any user defined patterns for date-time formatting.</li><li>java.text.Format is the parent class and java.text.SimpleDateFormat is the subclass of java.text.DateFormat class</li><li>Date formats are not synchronized. It is recommended to create seperate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.</li></ul><pre>import java.text.SimpleDateFormat;  <br>import java.util.Date;  <br><br>public class Example {  <br>  public static void main(String[] args) {  <br>    Date date = new Date();  <br>    SimpleDateFormat formatter = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);  <br>    String strDate= formatter.format(date);  <br>    System.out.println(&quot;Formatted Date: &quot; + strDate);<br>  }  <br>} </pre><h4>&gt; java.util.TimeZone</h4><ul><li>represents a time zone offset, and also figures out daylight savings.</li><li>get a TimeZone using getDefault which creates a TimeZone based on the time zone where the program is running.</li><li>Ex: a program running in India, getDefault creates a TimeZone object based on IST.</li></ul><pre>import java.util.*;  <br><br>public class TimeZoneExample4 {  <br>   public static void main( String args[] ){  <br>   TimeZone zone = TimeZone.getDefault();  <br>   String name = zone.getDisplayName();         <br>   System.out.println(&quot;Display name for default time zone: &quot;+ name);  <br>   }      <br>}  </pre><h3>Classes in Java 8 Date-Time API</h3><p>The new java.time API introduced in Java SE 8 is based on immutable value classes, making it thread-safe by design. It overcomes the shortcomings of the legacy APIs with a comprehensive, user-friendly, and consistent model for date-time handling.</p><ul><li><strong>Instant</strong> -&gt; Represents a moment on the timeline in UTC. Often used to timestamp events.</li><li><strong>Duration</strong> -&gt; Measures time in seconds and nanoseconds, useful for time-based calculations.</li><li><strong>LocalDate</strong> -&gt; Represents a date without a time zone, ideal for representing birthdays, anniversaries,…</li><li><strong>LocalTime</strong> -&gt; Represents time-of-day without a date or time zone.</li><li><strong>LocalDateTime</strong> -&gt; Combines date and time without time zone information.</li><li><strong>ZonedDateTime</strong> -&gt; Represents a date and time with a specific time zone.</li><li><strong>DateTimeFormatter</strong> -&gt; Formats and parses date-time objects. It’s thread-safe, unlike SimpleDateFormat</li></ul><pre>import java.time.LocalDate;<br>import java.time.LocalTime;<br>import java.time.ZonedDateTime;<br>import java.time.format.DateTimeFormatter;<br><br>public class Example {<br>   public static void main(String[] args) {<br>      LocalDate date = LocalDate.now();<br>      LocalTime time = LocalTime.now();<br>      ZonedDateTime zonedDateTime = ZonedDateTime.now();<br><br>      DateTimeFormatter formatter = DateTimeFormatter.ofPattern(&quot;yyyy-MM-dd HH:mm:ss z&quot;);<br>      System.out.println(&quot;Current Date: &quot; + date);<br>      System.out.println(&quot;Current Time: &quot; + time);<br>      System.out.println(&quot;Current ZonedDateTime: &quot; + formatter.format(zonedDateTime));<br>   }<br>}</pre><h3>References</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8Lq7Hv6tTSM&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8Lq7Hv6tTSM&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2F8Lq7Hv6tTSM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/323ea75bae59da48caefb5aca57977a9/href">https://medium.com/media/323ea75bae59da48caefb5aca57977a9/href</a></iframe><ul><li><a href="https://www.geeksforgeeks.org/util-date-class-methods-java-examples/">util.date class methods in Java with Examples - GeeksforGeeks</a></li><li><a href="https://www.javatpoint.com/java-util-timezone">java.util.TimeZone - Javatpoint</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b7fcc831374" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Promises vs Observables]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/promises-vs-observables-304320129326?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/304320129326</guid>
            <category><![CDATA[obbservables]]></category>
            <category><![CDATA[promises-in-javascript]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 08:01:54 GMT</pubDate>
            <atom:updated>2024-12-06T08:01:54.342Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*6Yq9Hd2DX5ckxnuJ.png" /></figure><h3>Promises</h3><p>A Promise object has two possible states; resolve and reject. It has <em>then</em><strong><em> ()</em></strong> to handle resolved states and <em>catch</em><strong><em> ()</em></strong> to handle rejected ones. Promises suitable for single asynchronous operations. Suitable for activities such as reading data from server, files. There are 4 phases in it: fulfilled, rejected, pending, and settled.</p><ul><li>Pending: In this, action is still pending and not yet fulfilled or rejected.</li><li>Fulfilled: This state represents that the asynchronous operation is successfully completed.</li><li>Rejected: In this action is rejected or failed.</li><li>Settled: In this result is determined successfully, either fulfilled or rejected.</li></ul><h4>syntax</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*z8VimjJVAw4wFEj8k8_m5g.png" /></figure><h3>Observables</h3><p>An Observable is a key concept that is in Angular through the RxJS<em> </em>library. These are a sequence of values that can be arrived at over time. These can send values either synchronously or asynchronously. Mainly used to handle streams of data that change over time.</p><h4>syntax</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*7chaVXHlERiGzxMQS-5H9Q.png" /></figure><p>We can write the same function using both promises and observers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*RZ0uxEAVNoyDHzIs5bKtRQ.png" /></figure><p>When you execute this you got the same result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/197/1*tCQFCs5QJEP57IioP3TWWA.png" /></figure><p>So why do we need both ways for one thing? Let’s look at the following example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*IRVfhmzpjMbeL4tq3YvDiA.png" /></figure><p>We provide multiple values to the observer and the promise and see the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/1*DuTHbvYagWPKNqm6aTEcoA.png" /></figure><p>We get one result from the promise and all results from the observer.</p><p>So one difference is promise returns only one result, while observer can keep returning multiple results even after it has done something.</p><p>In reactive programming and functional programming we can chain functions one after the other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*Jq_ILYCDEZFSB8Cw30Pc8Q.png" /></figure><p>In this example I filter the results, using <em>Ms</em> in observer. So it filter results like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/1*IdrRpcCRW521pAwrfjGXFg.png" /></figure><p>If I use the map function to change the result, like in the following code with the observer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*ITvjN2Uz51ziVNXpWhkCfQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*zeNxdCA0YrHmP5-Mv6sgKA.png" /></figure><p>I can use both map and filter functions like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*py8suChFNNfksBpQaUJHpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*CGq2bLzIQNIQmOjna9m6jg.png" /></figure><p>In a promise you cannot change the results. However, with an observer you can change the results. If you want to change the results, you need RxJS, and reactive programming.</p><h4>More…</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/0*vCcg77kyS_paNjh-.png" /></figure><h3>References</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYv2lRSUVokI%3Fstart%3D307%26feature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYv2lRSUVokI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYv2lRSUVokI%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d6d6a9ae0a424f38f9c0eaf7bf78b90/href">https://medium.com/media/9d6d6a9ae0a424f38f9c0eaf7bf78b90/href</a></iframe><ul><li><a href="https://stackoverflow.com/questions/37364973/what-is-the-difference-between-promises-and-observables">What is the difference between Promises and Observables?</a></li><li><a href="https://www.geeksforgeeks.org/what-is-the-difference-between-promises-and-observables-in-angular/">What is the Difference Between Promises and Observables in Angular ? - GeeksforGeeks</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=304320129326" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP Keep-Alive]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/http-keep-alive-with-http-comparisons-dc7e0167f018?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc7e0167f018</guid>
            <category><![CDATA[http-version]]></category>
            <category><![CDATA[http-keep-alive]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 07:57:40 GMT</pubDate>
            <atom:updated>2025-01-08T07:27:47.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z2x04JL9DEYwyhZmEEsdBA.jpeg" /></figure><p>HTTP keep-alive is an instruction that allows a single TCP connection to remain open for multiple HTTP requests.</p><p>By default, HTTP connections close after each request. <br>Ex: If you create 100 requests, you have to establish 100 new connections.</p><p>Enabling the keep-alive header allows to serve all web page resources over a single connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*xKLPUVW7joRvygVV.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kJq5OgsHpd_wLQVoFaqsIA.png" /></figure><h4>HTTP 1.0</h4><p>Under HTTP 1.0, connections should always be closed by the server after sending the response.</p><p>So developers of popular products started to add an unofficial extension named ‘keep-alive’ in order to allow the reuse of a connection for multiple requests/responses.</p><p>If the client supports keep-alive, it adds an additional header to the request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*NfrkDQs-SRxf9srC1t2HXA.png" /></figure><h4>HTTP 1.1</h4><p>In HTTP 1.1, all connections are considered persistent unless declared otherwise. The HTTP persistent connections do not use separate keepalive messages, they just allow multiple requests to use a single connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*MkfzvgbyOqtTars1iyUn8Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*MzBf_JHMi4gaHxvnuqssvw.png" /></figure><h4>Terms: QUIC, MIME, and TLS</h4><ul><li>QUIC (Quick UDP Internet Connections) -&gt; an experimental transport layer network protocol designed by Google. The overall goal is to reduce latency compared to that of TCP. Think of QUIC as being similar to TCP+TLS+HTTP/2 implemented on UDP.</li><li>MIME (Multipurpose Internet Mail Extensions) -&gt; an extension of the original Simple Mail Transport Protocol (SMTP) email protocol. It lets users exchange different kinds of data files, including audio, video, images and application programs, over email.</li><li>TLS (Transport Layer Security) -&gt; a widely adopted security protocol designed to facilitate privacy and data security for communications over the Internet. It is encrypting the communication between web applications and servers, such as web browsers loading a website.</li></ul><h3>Cons of HTTP Keep-alive</h3><p><a href="https://www.quora.com/Are-there-any-disadvantages-of-enabling-Keep-Alive-on-WebServer">Are there any disadvantages of enabling Keep-Alive on WebServer?</a></p><h3>References</h3><ul><li><a href="https://en.wikipedia.org/wiki/HTTP">HTTP - Wikipedia</a></li><li><a href="https://en.wikipedia.org/wiki/HTTP_persistent_connection">HTTP persistent connection - Wikipedia</a></li><li><a href="https://www.linkedin.com/pulse/http-10-vs-11-20-30-swadhin-pattnaik/">Boosting Web Performance: A Deep Dive into HTTP/1, HTTP/2, and HTTP/3</a></li><li><a href="https://www.linkedin.com/pulse/tcp-keep-alive-ibraham-ajazz/">TCP Keep Alive</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc7e0167f018" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding TCP using Wireshark]]></title>
            <link>https://medium.com/@dthrishala.siriwardhana/understanding-tcp-handshake-keep-alive-and-connection-termination-063a475a7c64?source=rss-4cbd6866bab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/063a475a7c64</guid>
            <category><![CDATA[tcp-handshake]]></category>
            <category><![CDATA[tcp]]></category>
            <category><![CDATA[keep-alive]]></category>
            <dc:creator><![CDATA[Dilmi Siriwardhana]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 07:55:26 GMT</pubDate>
            <atom:updated>2025-01-15T09:34:16.603Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*e5POlzt-Kp2flsju4OHaDA.png" /></figure><h3>Transport Protocols</h3><p>The Internet supports two transport layer protocols</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*IosRIfVcs284g5ItqvSQMw.png" /></figure><p>Message Oriented (UDP) -&gt; send data in distinct chunks/groups. (SMS)<br>Stream Oriented (TCP) -&gt; send a continuous flow of data. (phone call)</p><h3>TCP (Transmission Control Protocol)</h3><ul><li><strong>Connection oriented protocol</strong> <br>Before any data transfer, TCP establishes a connection<br>Server is waiting for a connection <br>Client contacts the server<br>Each connection is full duplex.</li><li><strong>Provides a reliable connection<br></strong>Receiver sends acknowledgements for segments.<br>TCP maintains a timer. If an ACK is not received in time, the segment is retransmitted.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*UdW9MiLM_aJi4nDEZMgQMg.png" /></figure><h4><strong>TCP maintains multiple timers</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*3J4qownyZVrVHJba5EagjQ.png" /></figure><h3>TCP Three Way Handshake</h3><p>Three Way Handshake is a process that is used to establish a connection between Client and Server. It has three steps of process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*_KvAtyBfBVj5AudY75gDbQ.png" /></figure><p>A tells B : it wants to open a connection.<br>B tells A : it accepts, and is ready to hear the next byte.<br>A tells B : it gets the accepted message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zIjGoRVb6tGjdv_RVO9Lw.png" /></figure><h3>Keep-alive</h3><p>Establishing a TCP connection requires a three way handshake, where the client and server exchange SYN, SYN-ACK, and ACK packets to synchronize communication</p><p>HTTP, which runs on top of TCP, uses a feature called keep-alive to allow the same TCP connection to remain open for multiple HTTP requests and responses. This eliminates the need to repeatedly establish new connection for each request.</p><p>Without keep-alive, if 100 HTTP requests are made, 100 separate connections would need to be established without keep-alive, which is inefficient. Keep alive improves performance by reusing the existing TCP connection.</p><h3>TCP Connection Termination (four way handshake)</h3><p>Client or server of the data flow must be shut down independently (half-close).<br>One end sends FIN, then it can’t send data.</p><p>Four steps involved: <br>1. A sends a FIN to B (active close) <br>2. B ACKs the FIN (B can still send data to A) <br>3. B sends FIN to A (passive close)<br>4. A ACKs the FIN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*DOGZMLxDcfHyQqtshq08JQ.png" /></figure><h4>Scenario 1</h4><p>When a client sends the FIN, and the connection needs to be closed. Then the client sends keep-alive probes to check if the connection is still active. Finally the connection is terminated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tE4kkxjv6VvotxByYpXKwg.png" /></figure><h4>Scenario 2</h4><p>If the server closing the connection, client ACK to that close. Since we close the browser, connection was closed from the client side as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pe43KrcxUvaTNVZcuaoXug.png" /></figure><h4>Scenario 3</h4><p>Server close the connection, we didn’t close the connection. We just send keep-alive probes and try to maintain the connection. Then server sends the reset packets to us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*14R8b_84HFnsXdmDQXr55g.png" /></figure><h3>References</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FUpUd5zEUUgI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DUpUd5zEUUgI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FUpUd5zEUUgI%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd4f20228c4954b36bd61109e0f7ab25/href">https://medium.com/media/dd4f20228c4954b36bd61109e0f7ab25/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=063a475a7c64" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>