<?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 Sajith Lakjaya on Medium]]></title>
        <description><![CDATA[Stories by Sajith Lakjaya on Medium]]></description>
        <link>https://medium.com/@sajithlakjaya?source=rss-27132bdcc2c5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*kwdVlYiNbhkIenls0Q8sig.jpeg</url>
            <title>Stories by Sajith Lakjaya on Medium</title>
            <link>https://medium.com/@sajithlakjaya?source=rss-27132bdcc2c5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:06:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sajithlakjaya/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[Best Practices for Building Next.js Applications]]></title>
            <link>https://medium.com/@sajithlakjaya/best-practices-for-building-next-js-applications-658162a1d7dc?source=rss-27132bdcc2c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/658162a1d7dc</guid>
            <dc:creator><![CDATA[Sajith Lakjaya]]></dc:creator>
            <pubDate>Sat, 01 Jun 2024 14:16:46 GMT</pubDate>
            <atom:updated>2024-06-01T14:16:46.381Z</atom:updated>
            <content:encoded><![CDATA[<p>Next.js, a React framework for production, is widely known for its ability to build fast, scalable, and SEO-friendly web applications. However, leveraging its full potential requires following certain best practices. Here’s a guide to help you build better Next.js applications with some coding samples.</p><h4>1. Project Structure</h4><p>A well-organized project structure enhances maintainability and scalability. Here’s a basic structure to get started:</p><pre>my-nextjs-app/<br>├── components/<br>│   ├── Header.js<br>│   ├── Footer.js<br>│   └── ...<br>├── pages/<br>│   ├── index.js<br>│   ├── about.js<br>│   └── ...<br>├── public/<br>│   ├── images/<br>│   └── ...<br>├── styles/<br>│   ├── globals.css<br>│   └── ...<br>├── utils/<br>│   └── api.js<br>├── .env.local<br>├── next.config.js<br>└── package.json</pre><h4>2. Use Static Generation and Server-Side Rendering Appropriately</h4><p>Next.js supports both Static Generation (SSG) and Server-Side Rendering (SSR). Choose the right method based on your needs.</p><p>Static Generation:</p><p>For pages that don’t change often (like blog posts, marketing pages).</p><pre>// pages/blog/[id].js<br>import { getAllPostIds, getPostData } from &#39;../../lib/posts&#39;;<br><br>export async function getStaticPaths() {<br>  const paths = getAllPostIds();<br>  return {<br>    paths,<br>    fallback: false,<br>  };<br>}<br>export async function getStaticProps({ params }) {<br>  const postData = await getPostData(params.id);<br>  return {<br>    props: {<br>      postData,<br>    },<br>  };<br>}<br>export default function Post({ postData }) {<br>  return (<br>    &lt;article&gt;<br>      &lt;h1&gt;{postData.title}&lt;/h1&gt;<br>      &lt;div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} /&gt;<br>    &lt;/article&gt;<br>  );<br>}</pre><p>Server-Side Rendering:</p><p>For pages that need fresh data on every request (like dashboards).</p><pre>// pages/dashboard.js<br>import { getSession } from &#39;next-auth/client&#39;;<br><br>export async function getServerSideProps(context) {<br>  const session = await getSession(context);<br>  if (!session) {<br>    return {<br>      redirect: {<br>        destination: &#39;/login&#39;,<br>        permanent: false,<br>      },<br>    };<br>  }<br>  return {<br>    props: { session },<br>  };<br>}<br>export default function Dashboard({ session }) {<br>  return &lt;div&gt;Welcome, {session.user.name}&lt;/div&gt;;<br>}</pre><h4>3. Optimize Performance</h4><p>Code Splitting:</p><p>Next.js automatically splits your code into smaller bundles, but you can further optimize it</p><pre>// Using dynamic import<br>import dynamic from &#39;next/dynamic&#39;;<br><br>const DynamicComponent = dynamic(() =&gt; import(&#39;../components/HeavyComponent&#39;));<br>export default function HomePage() {<br>  return (<br>    &lt;div&gt;<br>      &lt;DynamicComponent /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Image Optimization:</p><p>Next.js provides an Image component to optimize images</p><pre>import Image from &#39;next/image&#39;;<br><br>export default function Profile() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Image<br>        src=&quot;/me.png&quot;<br>        alt=&quot;Picture of the author&quot;<br>        width={500}<br>        height={500}<br>      /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>4. API Routes</h4><p>Next.js allows you to create API endpoints directly in the pages/api directory</p><pre>// pages/api/hello.js<br>export default function handler(req, res) {<br>  res.status(200).json({ text: &#39;Hello&#39; });<br>}</pre><h4>5. Environment Variables</h4><p>Use environment variables to manage different configurations for development, testing, and production</p><pre># .env.local<br>DATABASE_URL=your_database_url<br>API_KEY=your_api_key</pre><p>Access them in your code using process.env.</p><pre>const apiKey = process.env.API_KEY;</pre><h4>6. CSS and Styling</h4><p>Next.js supports various styling methods like CSS Modules, Styled JSX, and global CSS.</p><p>CSS Modules:</p><pre>// styles/Home.module.css<br>.container {<br>  background-color: #fafafa;<br>}</pre><pre>// pages/index.js<br>import styles from &#39;../styles/Home.module.css&#39;;<br><br>export default function Home() {<br>  return &lt;div className={styles.container}&gt;Hello World&lt;/div&gt;;<br>}</pre><h4>7. TypeScript</h4><p>Adding TypeScript to your Next.js project enhances type safety and developer experience.</p><pre># Install TypeScript and types<br>npm install --save-dev typescript @types/react @types/node</pre><p>Next, create a tsconfig.json file and start converting your .js files to .tsx or .ts.Copy code</p><pre>// pages/index.tsx<br>import { NextPage } from &#39;next&#39;;<br><br>const Home: NextPage = () =&gt; {<br>  return &lt;div&gt;Hello World&lt;/div&gt;;<br>};<br>export default Home;</pre><h4>Conclusion</h4><p>Following these best practices can significantly improve the performance, maintainability, and scalability of your Next.js applications. Experiment with different approaches, and always strive to optimize both the developer and user experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=658162a1d7dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up Apache Kafka Using Docker]]></title>
            <link>https://medium.com/@sajithlakjaya/install-apache-kafka-using-docker-12d2bc39203?source=rss-27132bdcc2c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/12d2bc39203</guid>
            <dc:creator><![CDATA[Sajith Lakjaya]]></dc:creator>
            <pubDate>Mon, 27 Feb 2023 13:43:52 GMT</pubDate>
            <atom:updated>2023-02-27T13:47:58.070Z</atom:updated>
            <content:encoded><![CDATA[<p>Apache Kafka is an open-source distributed streaming platform that is designed to handle real-time data streams. It is widely used for building real-time data pipelines and streaming applications. Setting up Kafka can be a complex task, but with the help of Docker, it can be simplified. Docker is a platform for developing, shipping, and running applications using containerization technology.</p><p>In this article, we will guide you through the process of setting up Apache Kafka using Docker. We will cover the following steps:</p><ol><li>Install Docker</li><li>Start ZooKeeper container</li><li>Start Kafka container</li><li>Test the Kafka cluster</li></ol><p>Step 1: Install Docker</p><p>The first step is to install Docker on your machine. You can download and install Docker from the official website for your operating system.</p><p>Step 2: Start ZooKeeper container</p><p>ZooKeeper is a distributed coordination service that is used by Kafka to manage its cluster state. To start a ZooKeeper container, open a terminal and run the following command:</p><pre>docker run -d --name zookeeper -p 2181:2181 zookeeper</pre><p>This command will download the ZooKeeper image from Docker Hub and start a container named “zookeeper”. The “-d” flag specifies that the container should run in detached mode, and the “-p” flag maps the container port 2181 to the host port 2181.</p><p>Step 3: Start Kafka container</p><p>To start a Kafka container, open a new terminal window and run the following command:</p><pre>docker run -d --name kafka -p 9092:9092 --link zookeeper:zookeeper -e KAFKA_ADVERTISED_HOST_NAME=localhost -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 wurstmeister/kafka</pre><p>This command will download the Kafka image from Docker Hub and start a container named “kafka”. The “-d” flag specifies that the container should run in detached mode, and the “-p” flag maps the container port 9092 to the host port 9092. The “ — link” flag links the Kafka container to the ZooKeeper container, and the “-e” flags specify environment variables for Kafka to use. The “KAFKA_ADVERTISED_HOST_NAME” environment variable sets the hostname or IP address that clients will use to connect to Kafka, and the “KAFKA_ZOOKEEPER_CONNECT” environment variable sets the ZooKeeper connection string.</p><p>Step 4: Test the Kafka cluster</p><p>To test the Kafka cluster, you can use the Kafka command-line tools that are included in the Kafka image. To do this, open a new terminal window and run the following command:</p><pre>docker exec -it kafka /bin/bash</pre><p>This command will start a Bash shell inside the Kafka container. You can then use the Kafka command-line tools to create a topic and produce and consume messages. For example, you can create a topic named “test” with the following command:</p><pre>kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic test</pre><p>This command creates a topic named “test” with one partition and one replication factor. You can then produce a message to the “test” topic with the following command:</p><pre>echo &quot;hello world&quot; | kafka-console-producer.sh --broker-list localhost:9092 --topic test</pre><p>This command produces a message with the text “hello world” to the “test” topic. You can then consume the message with the following command:</p><pre>kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning</pre><p>This command consumes messages from the “test” topic starting from the beginning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12d2bc39203" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>