<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://www.faizanbashir.me/feed.xml" rel="self" type="application/atom+xml" /><link href="https://www.faizanbashir.me/" rel="alternate" type="text/html" /><updated>2026-03-22T13:25:32+00:00</updated><id>https://www.faizanbashir.me/feed.xml</id><title type="html">Faizan Bashir</title><subtitle>Immerse in a tech enthusiast's world combining personal experiences, philosophical insights, and the latest tech trends. Engage with thought-provoking discussions and insights that challenge perspectives and spark innovation. Explore the limitless potential at the confluence of life and technology.</subtitle><entry><title type="html">Know Thyself: Alchemy of the Mind</title><link href="https://www.faizanbashir.me/know-thyself-alchemy-of-the-mind" rel="alternate" type="text/html" title="Know Thyself: Alchemy of the Mind" /><published>2024-01-13T03:13:00+00:00</published><updated>2024-01-13T03:13:00+00:00</updated><id>https://www.faizanbashir.me/know-thyself-alchemy-of-the-mind</id><content type="html" xml:base="https://www.faizanbashir.me/know-thyself-alchemy-of-the-mind"><![CDATA[<h1 id="know-thyself">Know Thyself!</h1>

<p>The “Know Thyself” series explores the vast expanse of what it means to be human, delving beyond the surface to understand the essence beneath our skin. It’s a journey into the heart of our humanity, seeking to unravel the complex tapestry of thoughts, emotions, and the silent conversations between ourselves. This endeavor is not just about peeling back the layers to reveal the biological underpinnings of our actions and reactions. Still, it’s an attempt to stitch together the myriad facets that make us uniquely human. From the echoes of our thoughts in the quiet of the night to the loud emotions that color our days, this series aims to explore every nuance, contradiction, and marvel of being human. Above all, “Know Thyself” is a deeply personal journey, a quest to understand the self and the world around us and to find meaning from our experiences.</p>

<p>As for “Alchemy of the Mind,” I wanted to share why this piece is so special. It’s like taking a lantern into the dark corners of our minds, illuminating the shadowy pathways where our thoughts and feelings intertwine, guided by the unseen hand of neurochemistry. This article is my way of saying that within each of us lies an alchemist capable of transforming the leaden weights of our experiences into the gold of insight and understanding. It’s a celebration of our inner complexities and a call to embrace the beautiful, bewildering, and ultimately transformative journey of self-discovery.</p>

<h2 id="the-alchemy-of-the-mind-unraveling-the-mysteries-of-mood-regulating-chemicals">The Alchemy of the Mind: Unraveling the Mysteries of Mood-Regulating Chemicals</h2>

<p>In the uncharted expanse of the human experience, where thoughts sail like ships in the night, there lies a profound mystery akin to the alchemical processes of old. This enigmatic journey, the quest to “Know Thyself,” is not merely a philosophical venture but a voyage into the essence of our being, guided by the stars of our internal cosmos—the chemicals of the mind. These neurochemicals, dopamine, serotonin, endorphins, cortisol, and oxytocin, among others, serve as the alchemists of our consciousness, transmuting the base metal of our experiences into the gold of our emotions, thoughts, and behaviors. In this article, we will journey through the intricate workings of these mood-regulating chemicals, unraveling the complex interplay of biology and emotion that defines the human experience.</p>

<h3 id="dopamine-the-reward-molecule">Dopamine: The Reward Molecule</h3>

<p>The first of these mood-regulating chemicals is dopamine, a neurotransmitter best known for its role in the brain’s reward system. Dopamine is often referred to as the “feel-good” chemical, as it is closely associated with feelings of pleasure, motivation, and satisfaction. This powerful neurotransmitter is released when we engage in rewarding experiences, such as physical activity, achieving a personal goal, or eating a delicious meal.</p>

<p>Dopamine plays a vital role in guiding our behavior by signaling the potential rewards of certain actions, thereby motivating us to pursue them. This process is essential for our survival, as it helps ensure that we prioritize activities that are beneficial to our well-being. However, the lure of dopamine can also lead to addictive behaviors, as individuals may become caught in a cycle of seeking out pleasurable experiences that trigger the release of this neurotransmitter.</p>

<h3 id="serotonin-the-happiness-regulator">Serotonin: The Happiness Regulator</h3>

<p>The second key player in our emotional symphony is serotonin, a neurotransmitter intimately linked to our overall sense of happiness and well-being. Serotonin is pivotal in regulating various mental and physical health aspects, including mood, appetite, sleep, and social behavior.</p>

<p>Low levels of serotonin have been linked to conditions such as depression and anxiety. Many antidepressant medications work by increasing the quantity of serotonin in the brain. Serotonin’s influence on our mood and well-being is also closely tied to our environment and lifestyle, with factors such as diet, exercise, and exposure to sunlight playing a crucial role in maintaining optimal serotonin levels.</p>

<h3 id="endorphins-natures-painkillers">Endorphins: Nature’s Painkillers</h3>

<p>Next up in our exploration of mood-regulating chemicals are endorphins, neurotransmitters that act as the body’s natural painkillers. The Endorphin neurotransmitters are released in response to stress or discomfort, helping alleviate pain and promote well-being. The name “endorphin” is derived from the words “endogenous,” which means produced within the body, and “morphine,” which is a potent pain-relieving drug.</p>

<p>One of the most well-known effects of endorphins is the so-called “runner’s high,” a euphoric sensation experienced by some individuals during intense physical activity. During exercise, the release of endorphins helps reduce the perception of pain and discomfort, allowing us to push through physical barriers and achieve new performance levels. Additionally, endorphins also regulate our mood and promote feelings of happiness and satisfaction, apart from their pain-relieving properties.</p>

<h3 id="cortisol-the-stress-hormone">Cortisol: The Stress Hormone</h3>

<p>Our emotional landscape would not be complete without the influence of cortisol, a hormone that plays a central role in regulating our stress responses. Cortisol, the neurotransmitter, is produced in the adrenal glands as a reaction to perceived threats or challenges, helping to mobilize energy reserves and sharpen our focus.</p>

<p>Cortisol is indispensable to our survival and well-being, but chronic stress can lead to prolonged elevations of this hormone, with potentially harmful consequences for our mental and physical health. High levels of cortisol have been associated with a range of health issues, including anxiety, depression, insomnia, and even increased risk of cardiovascular disease. As such, maintaining a healthy balance of cortisol is essential for our overall well-being.</p>

<p>Numerous strategies for managing stress and keeping cortisol levels in check include engaging in meditation, regular physical activity, practicing relaxation techniques such as meditation or deep breathing, and fostering strong social connections.</p>

<h3 id="oxytocin-the-love-hormone">Oxytocin: The Love Hormone</h3>

<p>Last but certainly not least, we have oxytocin, a hormone and neurotransmitter affectionately known as the “love hormone.” This unique neurotransmitter is crucial in promoting social bonding, trust, and emotional intimacy, helping forge and maintain the connections at the heart of our emotional well-being.</p>

<p>Oxytocin is released during various forms of social contact, including physical touch, hugging, and even simply gazing into the eyes of a loved one. The hormone is also involved in childbirth and breastfeeding, helping strengthen the bond between mother and child. In addition to promoting social attachment, oxytocin has been shown to have many other positive effects on our mood and well-being, including reducing stress, promoting relaxation, and even enhancing our ability to empathize with others.</p>

<h2 id="the-complex-interplay-of-mood-regulating-chemicals">The Complex Interplay of Mood-Regulating Chemicals</h2>

<p>As we have seen, our emotional landscape is shaped by the intricate interplay of various mood-regulating chemicals, each with its unique role in orchestrating our thoughts, feelings, and experiences. While dopamine, serotonin, endorphins, cortisol, and oxytocin are undoubtedly key players in this complex symphony, they represent just a fraction of the countless neurotransmitters and hormones contributing to human emotion’s rich tapestry.</p>

<p>It is essential to recognize that our emotions are not solely dictated by these chemicals but are the product of a complex interplay between our biology, environment, and personal experiences. Genetics, diet, physical activity, and social support all play an essential role in shaping our emotional well-being and must be considered alongside the contributions of these mood-regulating chemicals.</p>

<p>In our quest for happiness and emotional balance, we must take a holistic approach, nurturing our bodies and minds through healthy habits, strong relationships, and a deep appreciation for the beauty and complexity of the human experience. As we understand the intricate workings of our mood-regulating chemicals, we are better equipped to cultivate a life of emotional harmony and well-being guided by the wisdom of our own biology.</p>

<h2 id="conclusion">Conclusion</h2>

<p>In conclusion, the delicate dance of mood-regulating chemicals within our brains is a fascinating and complex process contributing to our emotional experiences. By understanding the roles of dopamine, serotonin, endorphins, cortisol, and oxytocin, we can better appreciate the intricate interplay of biology and emotion that defines our human experience. With this knowledge, we are empowered to pursue a balanced, healthy lifestyle that nurtures our emotional well-being and enables us to navigate the ever-changing landscape of our emotions with grace and resilience.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Writings" /><summary type="html"><![CDATA[The "Know Thyself" series embarks on a deep dive into the essence of human existence, exploring the intricate blend of biology, emotions, and thoughts that define us. "Alchemy of the Mind", a key piece in this series, shines a light on how our neurochemistry shapes our perceptions, emotions, and identities.]]></summary></entry><entry><title type="html">Know Thy World: You need more help than you think</title><link href="https://www.faizanbashir.me/know-thy-world-you-need-more-help-than-you-think" rel="alternate" type="text/html" title="Know Thy World: You need more help than you think" /><published>2023-12-31T03:13:00+00:00</published><updated>2023-12-31T03:13:00+00:00</updated><id>https://www.faizanbashir.me/know-thy-world-you-need-more-help-than-you-think</id><content type="html" xml:base="https://www.faizanbashir.me/know-thy-world-you-need-more-help-than-you-think"><![CDATA[<h1 id="the-invisible-forces-fighting-for-you">The invisible forces fighting for you</h1>

<p>Life, as we know it, is akin to an intricately choreographed dance. This ballet is not a solitary endeavor but involves an elaborate interplay of physical, chemical, biological, economic, political, educational, philosophical, religious, spiritual, and astronomical forces, each playing a crucial role in weaving the complex tapestry of existence. Even the wisest among us must grasp both their inner self and the complex world they inhabit. Surprisingly, one requires far more support and guidance than initially anticipated to make it through a single day. Indeed, you need more help than you think.</p>

<h2 id="pillars-of-creation-the-physical-and-chemical-titans">Pillars of Creation: The Physical and Chemical Titans</h2>

<p>From the moment we awaken, we are the beneficiaries of a vast, invisible network of physical and chemical processes. Consider the breath that revives us from sleep - a remarkable sequence of gaseous exchanges driven by the laws of diffusion and facilitated by the precise biological architecture of our lungs. The warmth of sunlight on our skin is made possible by the nuclear fusion reactions in the Sun’s core, its energy traversing the 93 million-mile gap to reach us.</p>

<p>Our meals, too, are marvels of chemical transformation. We bite into a slice of toast, not often contemplating the Maillard reaction that gives it its appealing color and flavor or the enzymatic processes that will convert it into usable energy within our bodies. Every glass of water we drink, every breath we draw, is a testament to the ceaseless interplay of physical and chemical laws that undergird our existence.</p>

<h2 id="sailing-the-ship-of-life-the-biological-symphonies">Sailing the Ship of Life: The Biological Symphonies</h2>

<p>Beyond the individual, we are part of a more comprehensive biological network that teems with life. From the microorganisms that populate our gut, aiding digestion and fortifying our immune system, to the bees that pollinate the fruits we enjoy - our life is deeply interconnected with countless other life forms. No matter how small, each organism contributes to the grand symphony of life. We thrive because they thrive and find their purpose in our survival.</p>

<p>Our bodies are akin to magnificent ships, navigated by the intricate symphonies of biological processes that work tirelessly beneath our conscious awareness. Among these, the immune system is a vigilant crew, a sophisticated defense network more complex and nuanced than any man-made security system. It’s a vigilant sentinel, discerning friend from foe, distinguishing between the cells that make up our physical being and the myriad of external invaders seeking entry. This remarkable system operates like an expertly trained army, equipped not just with frontline soldiers – the white blood cells – but also with a sophisticated intelligence network that remembers past invaders, ensuring quicker and more efficient responses to future threats.</p>

<p>Consider the marvel of a simple cut on your finger. This seemingly minor event sets off a cascade of biological responses. Platelets converge to form a clot and stem the bleeding, while white blood cells rush to the site, forming a barrier against potential infections. This response is akin to a well-coordinated naval blockade, preventing the invasion of pathogens while the skin, our protective barrier, is compromised. Meanwhile, specialized cells like scouts analyze the invaders, creating antibodies tailored specifically to neutralize them. It’s a symphony of processes, each tuned to the body’s needs, ensuring that even as we go about our daily lives, we are constantly and silently protected by this intricate and dynamic system.</p>

<h2 id="the-complex-interconnected-tapestry-tracing-the-economic-political-and-educational-threads">The Complex Interconnected Tapestry: Tracing the Economic, Political and Educational Threads</h2>

<p>Our waking hours are influenced by an intricate web of economic, political, and educational systems, each exerting subtle but profound influences on our daily experiences. Our ability to buy morning tea hinges on international trade agreements, labor laws, market forces, and the economic policies that govern them.</p>

<p>Political decisions shape our cities’ infrastructure, our neighborhoods’ safety, and air and water quality. They influence the job market, healthcare availability, and the extent of our civil liberties. Meanwhile, education equips us with the tools to navigate this multifaceted landscape, molding our worldview, skillsets, and life trajectories.</p>

<h2 id="meaning-of-life-the-religious-and-philosophical-underpinnings">Meaning of Life: The Religious and Philosophical Underpinnings</h2>

<p>Religion, for many, provides a moral and philosophical framework that guides their actions and choices. It offers a sense of community, shared values, and purpose that can provide comfort and motivation. For others, secular philosophies and ethical constructs serve a similar purpose, shaping attitudes and behaviors, fostering a sense of social responsibility, and inspiring efforts towards the common good.</p>

<p>On the spiritual front, religious beliefs provide a framework for understanding the world and our place in it. They offer moral guidance, cultivate a sense of community, and often bring solace in times of adversity. The teachings of various religions influence the social norms, laws, and even the political structures of numerous societies, underscoring their far-reaching impact.</p>

<h2 id="whirling-dervishes-the-spinning-particles-planets-stars-black-holes-and-galaxies">Whirling Dervishes: The Spinning Particles, Planets, Stars, Black Holes and Galaxies</h2>

<p>In the cosmic dance hall of the universe, everything from the tiniest particles to the vastest galaxies participates in a perpetual ballet of rotation and revolution. Just as whirling dervishes spin in their mesmerizing dances, every element of the cosmos partakes in this eternal twirl. Electrons orbit the nucleus of an atom in a delicate dance governed by the laws of quantum mechanics, a ballet so fundamental that it underpins the very structure of matter and life. On a grander scale, planets, including Earth, spin on their axes while simultaneously revolving around stars, creating the rhythms of day and night, seasons and years, each movement a part of the universe’s intricate choreography.</p>

<p>The direction of an electron’s spin, combined with its charge, influences how it interacts with other particles and fields. In atoms, the arrangement of electrons and their spins determines the atom’s chemical properties, leading to the formation of molecules, compounds, and, ultimately, all of the matter we see around us. Now, imagine if there were a sudden reverse of the spins of electrons – a shift from counter-clockwise to clockwise, for instance. Such a fundamental change could drastically alter the behavior of electrons and disrupt the architecture of atoms. Chemical reactions could behave differently, perhaps becoming less efficient or not occurring. The building blocks of life as we know it, from water to DNA, could be fundamentally altered, with potentially devastating consequences for life. Perhaps in some different Universe, the dance of the elections might be different than our own; life there would find novel ways to exist unknown to us.</p>

<p>The tilt of the Earth plays a critical role in sustaining life. The Earth’s tilt gives us our seasons, influencing the distribution of sunlight and affecting everything from weather patterns to plant growth. If the Earth’s tilt changes significantly, it could disrupt these patterns and have far-reaching implications for climate, ecosystems, and human society.</p>

<p>Look further, and you’ll see stars rotating, some at astonishing speeds, their spin influencing the generation of magnetic fields and the emission of light and energy. Even colossal black holes, those enigmatic titans at the center of galaxies, spin at incredible velocities, warping space-time around them. Galaxies themselves, vast spirals, ellipses, or irregular swirls of stars, dust, and dark matter, rotate over millions of years, each a tiny part of an ever-expanding universe. This celestial dance is not just for show; it’s the driving force behind many of the universe’s dynamic processes, from the birth of stars to the formation of galaxies. In this grand cosmic waltz, each spin and rotation is a verse in the poem of the cosmos, a testament to the forces that silently shape our universe and existence.</p>

<h2 id="cosmic-playground-universe--the-celestial-orchestra-of-life">Cosmic Playground: Universe – The Celestial Orchestra of Life</h2>

<p>In the vast expanse of the universe, a celestial orchestra plays a symphony that resonates through the fabric of existence. The cosmos is a playground where astronomical phenomena orchestrate a melody of life and creation. Each star, planet, comet, and galaxy contributes its unique note to this cosmic music. The Sun, our local maestro, conducts a daily and yearly rhythm essential for life on Earth. The warmth of its rays orchestrates the bloom of spring, the heat of summer, the harvest of autumn, and the slumber of winter. The Moon, our loyal companion in the sky, chimes in, controlling the tides and adding a gentle cadence to the Earth’s rotation. Its gravitational pull is an unseen yet powerful conductor in this orchestra.</p>

<p>The Sun, our star, burns brightly at the center of our solar system, providing the warmth and light necessary for life to thrive on Earth. Every sunrise that bathes our world in a golden hue, every plant that photosynthesizes sunlight into energy, and every weather pattern influenced by solar radiation is a testament to the Sun’s vital role in our existence. Our constant companion in our night sky, the Moon, its gravitational pull governing the ebb and flow of our ocean tides. This lunar influence, subtle yet profound, affects marine life and climate, thereby indirectly influencing our own lives.</p>

<p>Beyond our solar system, the universe’s grand scale reveals even more of this harmonious interplay. The life cycles of stars, from their fiery births in nebulae to their spectacular demises as supernovae, are like epic operas narrating the story of the cosmos. These cosmic events awe us with their beauty and play a crucial role in disseminating elements – the very building blocks of life. As these elements travel across the cosmos, they eventually find new homes, creating planets, moons, and even the seeds for life. In this immense cosmic playground, every movement, from a galaxy’s spin to the flutter of a comet’s tail, contributes to a grand celestial performance, a testament to the dynamic and ever-evolving universe that cradles us in its vast, mysterious embrace.</p>

<h2 id="the-web-of-existence-acknowledging-our-interdependence">The Web of Existence: Acknowledging Our Interdependence</h2>

<p>In the intricate web of existence, every thread of life is interwoven in a complex tapestry that underscores our profound interdependence. This interconnectedness spans from the microscopic bacteria that enrich our soil, fostering the growth of the food we eat, to the vast networks of human innovation and collaboration that construct our societies. It’s a symbiotic dance where every creature, every plant, and every organism plays a crucial role. The bees that pollinate our crops, the trees that purify our air, and the waters that sustain us are not mere backdrops in our lives but active participants in our survival and well-being. Similarly, the social structures, economies, and cultural institutions we’ve built are not standalone entities but interlinked systems where changes in one ripple across the others, affecting us all.</p>

<p>Recognizing these interconnected strands is more than an exercise in gratitude. It underscores our profound interdependence - with nature, fellow human beings, and societal structures that we often take for granted. It humbles us, reminding us of the multitude of seen and unseen forces that align to make our lives possible and challenges us to contribute, in our unique ways, to this extraordinary dance of existence. It invites us to view ourselves not as solitary actors but as part of a vast, complex system in which our actions reverberate far beyond our immediate sphere of influence. And in doing so, it encourages us to tread with care, respect, and a sense of responsibility towards the world that cradles us.</p>

<p>Within this web, our actions, no matter how small, have far-reaching impacts. The products we consume, the energy we use, and daily choices send ripples through this vast network, affecting ecosystems, climates, and communities globally. Recognizing this interdependence is vital for understanding our place and guiding our actions toward sustainability and harmony. It invites us to act with greater mindfulness and compassion, understanding that the health of one is linked to the well-being of all. In this web of existence, we find our most significant challenges and profound opportunities for growth, connection, and collective thriving.</p>

<h2 id="conclusion">Conclusion</h2>

<p>In conclusion, understanding the myriad systems and processes that shape our existence helps us appreciate the profound interconnectedness of life. It also reminds us that we receive countless blessings, often overlooked in the humdrum of daily life. The more we understand our world, the better we can navigate its challenges and contribute meaningfully to its betterment. After all, we need more help than we think to live this beautiful, complex life. Acknowledging this is the first step towards a more conscious, appreciative existence, the first step to knowing thyself.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Writings" /><summary type="html"><![CDATA[Explore the unseen forces shaping our lives, Know Thy World. From the symphony of biological processes to the cosmic dance of the universe, discover how interconnected and dependent we are on these hidden powers.]]></summary></entry><entry><title type="html">Weaving the Tales of Life: The Power of Storytelling</title><link href="https://www.faizanbashir.me/weaving-the-tales-of-life-the-power-of-storytelling" rel="alternate" type="text/html" title="Weaving the Tales of Life: The Power of Storytelling" /><published>2023-07-07T03:13:00+00:00</published><updated>2023-07-07T03:13:00+00:00</updated><id>https://www.faizanbashir.me/weaving-the-tales-of-life-the-power-of-storytelling</id><content type="html" xml:base="https://www.faizanbashir.me/weaving-the-tales-of-life-the-power-of-storytelling"><![CDATA[<h1 id="storytelling">Storytelling</h1>

<p>Human civilization has been weaving the tapestry of life and death with colorful and intricate storytelling threads since humanity’s dawn. Reverberating with the rhythm of our hearts, storytelling etches vivid pictures on the mind’s canvas, offering a glimpse into the depth and breadth of the human experience. An instrumental communication tool, storytelling has long shaped our societies, touched our souls, ignited our imaginations, and flamed the fires of war.</p>

<h2 id="importance-of-storytelling">Importance of Storytelling</h2>

<p>Our deep-rooted love for stories reflects our intrinsic need for human connection and effective communication. A well-crafted story can stir emotions, fuel empathy, and foster a sense of belonging. Through stories, we share experiences, teach values, and carry forward the wisdom of generations. Stories shape our minds, fashion our morals, influence our behavior, and configure our personalities. Stories have helped us make sense of the world around us for many millennia.</p>

<p>Storytelling has a tremendous impact on education. Well-articulated stories captivate our attention, sparking curiosity and encouraging creativity. Stories are easy to remember, thus facilitating learning and memory. Complex ideas are made more accessible using well-crafted accounts, igniting the spark of discovery and the joy of learning.</p>

<h2 id="weaving-the-fabric-of-nations-societies-and-communities">Weaving the fabric of Nations, Societies, and Communities</h2>

<p>From the tribal circles of ancient civilizations to modern digital platforms, storytelling has been at the heart of building nations, societies, and communities. Through fascinating myths, awe-inspiring legends, and heart-warming folklore, our ancestors established social norms, defined moral codes, and explained the mysteries of the universe as they perceived these realities. These stories have long united communities, providing a shared sense of history, culture, identity, and belonging.</p>

<p>Tales like the Epic of Gilgamesh, the Iliad and the Odyssey, the Ramayana, and the Mahabharata were more than mere entertainment. These narrative tools embodied their respective societies’ values, serving as moral compasses and societal blueprints for generations.</p>

<h2 id="spinning-the-tangled-threads-of-propaganda">Spinning the tangled threads of Propaganda</h2>

<p>Storytelling has been used to spin the tangled threads of Propaganda. From political regimes to social movements, the battle of narratives has been waged for ages to sway public opinion, promote ideologies, and justify actions. The narratives of the ‘American Dream’ in the modern-day United States of America, the ‘Aryan supremacy’ in Nazi Germany, and the ‘Classless Society’ in the Communist Soviet Propaganda are all testaments to the influence of stories in shaping societal realities.</p>

<h2 id="embellishing-the-golden-threads-of-spirituality-and-religion">Embellishing the Golden Threads of Spirituality and Religion</h2>

<p>Religion and storytelling are weaved in a spiritual union that speaks to our deeply rooted yearnings for purpose and connection. Biblical parables, Quranic narratives, Buddhist Jatakas, and Hindu Puranas all utilize the power of stories to convey religious philosophies and moral lessons. Through tales of divinity, struggles of extraordinary men, moral conflicts, miracles, and punishments, religions have effectively used stories to inspire faith, guide moral behavior, and foster a sense of community among followers.</p>

<h2 id="interlacing-customers-with-dexterity-the-business-of-wants">Interlacing Customers with Dexterity: The Business of Wants</h2>

<p>Storytelling has long emerged as a strategic tool for building brands and driving sales in business. A compelling dexterous story can bring a product to life, connecting with consumers emotionally. The magic of storytelling transmutes a need into a want. It’s not about selling a product; it’s about selling a narrative that resonates with the people.</p>

<p>The success of luxury brands like Rolex or Louis Vuitton is a testament to this reality. They sell more than just watches or handbags; they sell a lifestyle, a status symbol. Consumer perception relates luxury brands to a lifestyle rather than a commodity. Luxury brands’ history of crafting sophisticated stories of exclusivity, craftsmanship, and heritage makes their high price tags seem justified and desirable.</p>

<p>Storytelling as an art form has made a formidable impact in the business world, perhaps nowhere more so than in the wild success of companies such as Apple and De Beers. These enterprises have leveraged the emotional power of narratives to shape their brand identities and redefine markets and consumer behavior. They appeal more to the emotions than the mind.</p>

<h3 id="apple-the-apple-of-our-eyes">Apple: The Apple of our eyes</h3>

<p>Since its inception, Apple has produced as many compelling narratives as its cutting-edge technology and innovations. Steve Jobs, the world-famous co-founder and former CEO of Apple, very early realized the power of storytelling and leveraged it to great advantage. He understood that consumers were not just buying a product; they were buying into a story, a lifestyle, an experience. Even today, the iPhone is more of a status symbol than just a phone.</p>

<p>Whether using the 1984 Super Bowl commercial, symbolizing a rebellion against conformity and the triumph of individuality, to the “Think Different” campaign, Apple’s stories have always been about more than its products. Apple portrayed its users as pioneers, change-makers, and people who choose to “Think Differently”, ushering a sense of haves and have not’s. Apple positioned its products as tools that unlock creativity, embody a blend of art, technology, and utility. This cleverly engineered narrative was critical in fostering a virtually cult-like following that has propelled Apple to its trillion-dollar status.</p>

<h3 id="de-beers-the-deal-is-forever">De Beers: The Deal is Forever</h3>

<p>Diamonds weren’t always a woman’s best friend or the necessity of engagement proposals. The transformation of these sharp-edged, well-polished lumps of Carbon into symbols of eternal love and commitment is primarily credited to a marketing masterstroke by De Beers, a major player in the diamond industry. Diamonds on Earth may be hard to come by, but it <a href="https://www.space.com/diamond-rain-atmosphere-uranus-neptune">rains Diamonds on Uranus and Neptune</a>.</p>

<p>Back in the 1930s, De Beers faced a slump in diamond sales due to the Great Depression. To increase the sale of Diamonds, De Beers launched the celebrated ad campaign: “A Diamond is Forever”. The narrative associated diamonds with an unbreakable bond of love and commitment. Unexpectedly, a diamond engagement ring transcended its utility as mere jewelry; it had become the testament to enduring love, a symbol of a commitment as indestructible and precious as the Diamond.</p>

<p>The storytelling genius of De Beers not only propelled diamond sales but also effectively created a tradition that endures to this day. De Beers’ story has been so compelling that despite economic fluctuations and changing societal norms, the tradition of diamond engagement rings has gained widespread acceptance.</p>

<h2 id="knitting-the-bonds-of-family">Knitting the Bonds of Family</h2>

<p>Storytelling plays a significant role in the intimate sphere of family life, the building blocks of nations, societies, and communities. Narratives spun from the intertwined threads of shared experiences and inherited histories weave the fabric that binds families together, crafting a sense of identity and belonging spanning generations.</p>

<p>Storytelling takes on a unique and nurturing role in the family setting. They are essential building blocks of personal identity. Through stories of ancestors’ resilience, misfortunes, struggles, and accomplishments, children learn about their roots, values, and familial bonds that connect them to a past extending beyond the individual experience. They offer a sense of continuity and connectedness that anchors the family unit, shaping a shared familial identity that transcends the individual and binds members together across generations. From bedtime tales to sharing family lore passed down through generations, stories are integral to forming a child’s understanding of their heritage and place in the world.</p>

<p>Likewise, stories shared within the family can act as powerful teaching tools. Parables and anecdotes of past experiences can impart essential life lessons and moral values, guiding younger members as they navigate the world. Lessons learned from Grandma’s perseverance during hard times or Grandpa’s ingenious solution to a challenging problem can inspire and instruct in equal measure. Storytelling fosters understanding and empathy. Hearing about a sibling’s accomplishment or a parent’s childhood can provide insights into their perspectives and experiences, nurturing stronger bonds and promoting mutual respect.</p>

<p>In the digital age, narratives shared via video calls or in family groups keep the essence of this tradition alive, maintaining the sense of shared identity and belonging. Storytelling within families is a powerful medium of education, preservation of heritage, instilling values, and encouraging bonding. As we confront the world, the stories from our hearth help shape us, grounding us in our identities while teaching us about resilience, love, and the complex tapestry of human experience.</p>

<h2 id="conclusion">Conclusion</h2>

<p>Storytelling can be a powerful catalyst for business success. Transcending the boundaries of traditional marketing, storytelling fosters emotional connections providing a sense of purpose and identity that can turn customers into advocates and even evangelists. Whether it’s a tech giant like Apple rousing emotions with inspiring innovation and creativity or De Beers turning diamonds into symbols of love and commitment, storytelling continues to shape our economic landscapes profoundly.</p>

<p>In the era of information super explosion, storytelling remains a beacon of genuine human connection. A bridge to the past, a lens into the future, and a compass in the present. Stories act as a beacon while we navigate the labyrinth of life, reflecting triumphs, trials, dreams, fears, and achievements.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Writings" /><summary type="html"><![CDATA[Our deep-rooted love for stories reflects our intrinsic need for human connection and effective communication. A well-crafted story can stir emotions, fuel empathy, and foster a sense of belonging. Through stories, we share experiences, teach values, and carry forward the wisdom of generations.]]></summary></entry><entry><title type="html">Automating Deployment of Applications using Kubernetes Python SDK</title><link href="https://www.faizanbashir.me/automating-deployment-of-python-applications-kubernetes-sdk" rel="alternate" type="text/html" title="Automating Deployment of Applications using Kubernetes Python SDK" /><published>2023-06-19T10:00:00+00:00</published><updated>2023-06-19T10:00:00+00:00</updated><id>https://www.faizanbashir.me/automating-deployment-of-python-applications-kubernetes-sdk</id><content type="html" xml:base="https://www.faizanbashir.me/automating-deployment-of-python-applications-kubernetes-sdk"><![CDATA[<h1 id="automating-kubernetes-deployments-using-python">Automating Kubernetes Deployments using Python</h1>

<p>Kubernetes has become the go-to orchestration platform for deploying, scaling, and managing containerized applications. Automating the deployment of applications can streamline the process and increase productivity. In this article, we’ll demonstrate how to use the Python Kubernetes SDK to automate the deployment of an Nginx application to a Kubernetes cluster.</p>

<h1 id="prerequisites">Prerequisites</h1>

<p>Before we start, make sure you have the following:</p>

<ul>
  <li>Python 3 and <code class="language-plaintext highlighter-rouge">pip</code> installed.</li>
  <li>Kubernetes CLI <code class="language-plaintext highlighter-rouge">kubectl</code> installed and configured.</li>
</ul>

<hr />

<h1 id="table-of-contents">Table of Contents</h1>

<ul>
  <li><a href="#setting-up-the-python-kubernetes-sdk">Setting up the Python Kubernetes SDK</a></li>
  <li><a href="#creating-a-kubernetes-deployment">Creating a Kubernetes Deployment</a></li>
  <li><a href="#creating-a-kubernetes-service">Creating a Kubernetes Service</a></li>
  <li><a href="#creating-a-kubernetes-secret">Creating a Kubernetes Secret</a></li>
  <li><a href="#creating-a-kubernetes-configmap">Creating a Kubernetes ConfigMap</a></li>
  <li><a href="#creating-a-kubernetes-ingress">Creating a Kubernetes Ingress</a></li>
  <li><a href="#conclusion">Conclusion</a></li>
</ul>

<hr />

<h1 id="setting-up-the-python-kubernetes-sdk">Setting up the Python Kubernetes SDK</h1>
<p>Before we start, make sure you have the Python Kubernetes SDK installed. If not, install it using pip:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">pip</span> <span class="n">install</span> <span class="n">kubernetes</span></code></pre></figure>

<p>You must also have a valid kubeconfig file for your Kubernetes cluster. This file provides the necessary information for connecting to the kubernetes cluster, such as the cluster API endpoint and authentication details.</p>

<h1 id="creating-a-kubernetes-deployment">Creating a Kubernetes Deployment</h1>
<p>Deployments are Kubernetes resources that describe the desired state for an application, including the number of replicas, container images, and update strategy.</p>

<p>First, let’s import the necessary classes and create a client to interact with the Kubernetes API:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">kubernetes</span> <span class="kn">import</span> <span class="n">client</span><span class="p">,</span> <span class="n">config</span>

<span class="c1"># Load the kubeconfig file
</span><span class="n">config</span><span class="p">.</span><span class="n">load_kube_config</span><span class="p">()</span>

<span class="c1"># Create a client instance
</span><span class="n">api_instance</span> <span class="o">=</span> <span class="n">client</span><span class="p">.</span><span class="n">AppsV1Api</span><span class="p">()</span></code></pre></figure>

<p>Next, we’ll create an Nginx deployment with one replica:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">kubernetes.client</span> <span class="kn">import</span> <span class="n">V1Deployment</span><span class="p">,</span> <span class="n">V1DeploymentSpec</span><span class="p">,</span> <span class="n">V1PodTemplateSpec</span><span class="p">,</span> <span class="n">V1PodSpec</span><span class="p">,</span> <span class="n">V1Container</span><span class="p">,</span> <span class="n">V1ObjectMeta</span>

<span class="c1"># Define the deployment metadata
</span><span class="n">metadata</span> <span class="o">=</span> <span class="n">V1ObjectMeta</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"nginx-deployment"</span><span class="p">)</span>

<span class="c1"># Define the deployment spec
</span><span class="n">spec</span> <span class="o">=</span> <span class="n">V1DeploymentSpec</span><span class="p">(</span>
    <span class="n">replicas</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
    <span class="n">template</span><span class="o">=</span><span class="n">V1PodTemplateSpec</span><span class="p">(</span>
        <span class="n">metadata</span><span class="o">=</span><span class="n">V1ObjectMeta</span><span class="p">(</span><span class="n">labels</span><span class="o">=</span><span class="p">{</span><span class="s">"app"</span><span class="p">:</span> <span class="s">"nginx"</span><span class="p">}),</span>
        <span class="n">spec</span><span class="o">=</span><span class="n">V1PodSpec</span><span class="p">(</span>
            <span class="n">containers</span><span class="o">=</span><span class="p">[</span>
                <span class="n">V1Container</span><span class="p">(</span>
                    <span class="n">name</span><span class="o">=</span><span class="s">"nginx"</span><span class="p">,</span>
                    <span class="n">image</span><span class="o">=</span><span class="s">"nginx:1.14.2"</span><span class="p">,</span>
                    <span class="n">ports</span><span class="o">=</span><span class="p">[{</span><span class="s">"containerPort"</span><span class="p">:</span> <span class="mi">80</span><span class="p">}],</span>
                <span class="p">)</span>
            <span class="p">]</span>
        <span class="p">),</span>
    <span class="p">),</span>
    <span class="n">selector</span><span class="o">=</span><span class="p">{</span><span class="s">"matchLabels"</span><span class="p">:</span> <span class="p">{</span><span class="s">"app"</span><span class="p">:</span> <span class="s">"nginx"</span><span class="p">}},</span>
<span class="p">)</span>

<span class="c1"># Create the deployment object
</span><span class="n">deployment</span> <span class="o">=</span> <span class="n">V1Deployment</span><span class="p">(</span><span class="n">metadata</span><span class="o">=</span><span class="n">metadata</span><span class="p">,</span> <span class="n">spec</span><span class="o">=</span><span class="n">spec</span><span class="p">)</span>

<span class="c1"># Create the deployment on the cluster
</span><span class="n">api_instance</span><span class="p">.</span><span class="n">create_namespaced_deployment</span><span class="p">(</span><span class="n">namespace</span><span class="o">=</span><span class="s">"default"</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">deployment</span><span class="p">)</span></code></pre></figure>

<h1 id="creating-a-kubernetes-service">Creating a Kubernetes Service</h1>

<p>Services are Kubernetes resources that define how to access an application running in a set of Pods. In our example, we’ll create a simple NodePort service to expose the Nginx deployment:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">kubernetes.client</span> <span class="kn">import</span> <span class="n">V1Service</span><span class="p">,</span> <span class="n">V1ServiceSpec</span><span class="p">,</span> <span class="n">V1ServicePort</span>

<span class="c1"># Define the service metadata
</span><span class="n">metadata</span> <span class="o">=</span> <span class="n">V1ObjectMeta</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"nginx-service"</span><span class="p">)</span>

<span class="c1"># Define the service spec
</span><span class="n">spec</span> <span class="o">=</span> <span class="n">V1ServiceSpec</span><span class="p">(</span>
    <span class="n">selector</span><span class="o">=</span><span class="p">{</span><span class="s">"app"</span><span class="p">:</span> <span class="s">"nginx"</span><span class="p">},</span>
    <span class="n">ports</span><span class="o">=</span><span class="p">[</span><span class="n">V1ServicePort</span><span class="p">(</span><span class="n">port</span><span class="o">=</span><span class="mi">80</span><span class="p">,</span> <span class="n">target_port</span><span class="o">=</span><span class="mi">80</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="s">"TCP"</span><span class="p">)],</span>
    <span class="nb">type</span><span class="o">=</span><span class="s">"NodePort"</span><span class="p">,</span>
<span class="p">)</span>

<span class="c1"># Create the service object
</span><span class="n">service</span> <span class="o">=</span> <span class="n">V1Service</span><span class="p">(</span><span class="n">metadata</span><span class="o">=</span><span class="n">metadata</span><span class="p">,</span> <span class="n">spec</span><span class="o">=</span><span class="n">spec</span><span class="p">)</span>

<span class="c1"># Create the service on the cluster
</span><span class="n">api_instance</span> <span class="o">=</span> <span class="n">client</span><span class="p">.</span><span class="n">CoreV1Api</span><span class="p">()</span>
<span class="n">api_instance</span><span class="p">.</span><span class="n">create_namespaced_service</span><span class="p">(</span><span class="n">namespace</span><span class="o">=</span><span class="s">"default"</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">service</span><span class="p">)</span></code></pre></figure>

<h1 id="creating-a-kubernetes-secret">Creating a Kubernetes Secret</h1>

<p>Secrets are Kubernetes resources that store sensitive information like passwords, tokens, and keys. In this section, we’ll create a simple Kubernetes secret containing an example API key:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">kubernetes.client</span> <span class="kn">import</span> <span class="n">V1Secret</span>

<span class="c1"># Define the secret metadata
</span><span class="n">metadata</span> <span class="o">=</span> <span class="n">V1ObjectMeta</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"example-api-key"</span><span class="p">)</span>

<span class="c1"># Define the secret data
</span><span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s">"api-key"</span><span class="p">:</span> <span class="s">"c2VjcmV0YXBpa2V5"</span><span class="p">}</span>  <span class="c1"># base64 encoded string "secretapikey"
</span>
<span class="c1"># Create the secret object
</span><span class="n">secret</span> <span class="o">=</span> <span class="n">V1Secret</span><span class="p">(</span><span class="n">metadata</span><span class="o">=</span><span class="n">metadata</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>

<span class="c1"># Create the secret on the cluster
</span><span class="n">api_instance</span> <span class="o">=</span> <span class="n">client</span><span class="p">.</span><span class="n">CoreV1Api</span><span class="p">()</span>
<span class="n">api_instance</span><span class="p">.</span><span class="n">create_namespaced_secret</span><span class="p">(</span><span class="n">namespace</span><span class="o">=</span><span class="s">"default"</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">secret</span><span class="p">)</span></code></pre></figure>

<h1 id="creating-a-kubernetes-configmap">Creating a Kubernetes ConfigMap</h1>

<p>ConfigMaps are Kubernetes resources that allow you to store and manage non-sensitive configuration information, such as application settings. In this example, we’ll create a ConfigMap containing a sample configuration file:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">kubernetes.client</span> <span class="kn">import</span> <span class="n">V1ConfigMap</span>

<span class="c1"># Define the ConfigMap metadata
</span><span class="n">metadata</span> <span class="o">=</span> <span class="n">V1ObjectMeta</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"example-config"</span><span class="p">)</span>

<span class="c1"># Define the ConfigMap data
</span><span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s">"config.yaml"</span><span class="p">:</span> <span class="s">"example: configuration</span><span class="se">\n</span><span class="s">data: goes here"</span><span class="p">}</span>

<span class="c1"># Create the ConfigMap object
</span><span class="n">config_map</span> <span class="o">=</span> <span class="n">V1ConfigMap</span><span class="p">(</span><span class="n">metadata</span><span class="o">=</span><span class="n">metadata</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>

<span class="c1"># Create the ConfigMap on the cluster
</span><span class="n">api_instance</span> <span class="o">=</span> <span class="n">client</span><span class="p">.</span><span class="n">CoreV1Api</span><span class="p">()</span>
<span class="n">api_instance</span><span class="p">.</span><span class="n">create_namespaced_config_map</span><span class="p">(</span><span class="n">namespace</span><span class="o">=</span><span class="s">"default"</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">config_map</span><span class="p">)</span></code></pre></figure>

<h1 id="creating-a-kubernetes-ingress">Creating a Kubernetes Ingress</h1>

<p>Ingress is a Kubernetes resource that manages external access to services within the cluster, typically via HTTP or HTTPS. We will create a simple ingress rule that routes traffic to our Nginx service:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">kubernetes.client</span> <span class="kn">import</span> <span class="n">V1Ingress</span><span class="p">,</span> <span class="n">V1IngressSpec</span><span class="p">,</span> <span class="n">V1IngressRule</span><span class="p">,</span> <span class="n">V1HTTPIngressRuleValue</span><span class="p">,</span> <span class="n">V1IngressBackend</span>

<span class="c1"># Define the Ingress metadata
</span><span class="n">metadata</span> <span class="o">=</span> <span class="n">V1ObjectMeta</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"example-ingress"</span><span class="p">)</span>

<span class="c1"># Define the Ingress spec
</span><span class="n">spec</span> <span class="o">=</span> <span class="n">V1IngressSpec</span><span class="p">(</span>
    <span class="n">rules</span><span class="o">=</span><span class="p">[</span>
        <span class="n">V1IngressRule</span><span class="p">(</span>
            <span class="n">host</span><span class="o">=</span><span class="s">"example.com"</span><span class="p">,</span>
            <span class="n">http</span><span class="o">=</span><span class="n">V1HTTPIngressRuleValue</span><span class="p">(</span>
                <span class="n">paths</span><span class="o">=</span><span class="p">[</span>
                    <span class="p">{</span>
                        <span class="s">"path"</span><span class="p">:</span> <span class="s">"/"</span><span class="p">,</span>
                        <span class="s">"backend"</span><span class="p">:</span> <span class="n">V1IngressBackend</span><span class="p">(</span><span class="n">service_name</span><span class="o">=</span><span class="s">"nginx-service"</span><span class="p">,</span> <span class="n">service_port</span><span class="o">=</span><span class="mi">80</span><span class="p">),</span>
                    <span class="p">}</span>
                <span class="p">]</span>
            <span class="p">),</span>
        <span class="p">)</span>
    <span class="p">],</span>
<span class="p">)</span>

<span class="c1"># Create the Ingress object
</span><span class="n">ingress</span> <span class="o">=</span> <span class="n">V1Ingress</span><span class="p">(</span><span class="n">metadata</span><span class="o">=</span><span class="n">metadata</span><span class="p">,</span> <span class="n">spec</span><span class="o">=</span><span class="n">spec</span><span class="p">)</span>

<span class="c1"># Create the Ingress on the cluster
</span><span class="n">api_instance</span> <span class="o">=</span> <span class="n">client</span><span class="p">.</span><span class="n">NetworkingV1Api</span><span class="p">()</span>
<span class="n">api_instance</span><span class="p">.</span><span class="n">create_namespaced_ingress</span><span class="p">(</span><span class="n">namespace</span><span class="o">=</span><span class="s">"default"</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">ingress</span><span class="p">)</span></code></pre></figure>

<p>By following the steps outlined in this article and using the Python Kubernetes SDK, you can automate the deployment and management of your kubernetes applications. This will streamline your workflows, reduce the chance of human error, and increase overall efficiency.</p>

<h1 id="conclusion">Conclusion</h1>

<p>In conclusion, the Python Kubernetes SDK effectively automates application deployment and manages Kubernetes resources. With the examples in this article, you can easily create Kubernetes deployments, services, secrets, ConfigMaps, and ingress rules. By integrating this SDK into your development workflow, you can streamline processes, reduce the risk of human error, and increase overall efficiency, allowing you to focus on developing robust, scalable, and innovative applications for the Kubernetes platform.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Python" /><category term="Kubernetes" /><summary type="html"><![CDATA[Learn how to use the Python Kubernetes SDK to automate application deployments, including creating Kubernetes resources like deployments, services, secrets, config maps, and ingress.]]></summary></entry><entry><title type="html">Lines of Destiny: The Immaculate Beauty of the Arabic Alphabet</title><link href="https://www.faizanbashir.me/lines-of-destiny-the-immaculate-beauty-of-the-arabic-alphabet" rel="alternate" type="text/html" title="Lines of Destiny: The Immaculate Beauty of the Arabic Alphabet" /><published>2023-06-19T03:13:00+00:00</published><updated>2023-06-19T03:13:00+00:00</updated><id>https://www.faizanbashir.me/lines-of-destiny-the-immaculate-beauty-of-the-arabic-alphabet</id><content type="html" xml:base="https://www.faizanbashir.me/lines-of-destiny-the-immaculate-beauty-of-the-arabic-alphabet"><![CDATA[<h1 id="lines-of-destiny">Lines of Destiny</h1>

<p>The Arabic alphabet is a fascinating script with a rich history and a unique structure that has captivated scholars, artists, and linguists for centuries. Long has Arabic enchanted people with the ebb and flow of its peerless scripts adorning books, walls, and even hearts. The Arabic alphabet has inspired countless masterpieces with its flowing calligraphy and elegant curves throughout the arena of time. This article delves into the Arabic alphabet’s origins, structure, and timeless beauty, revealing the complex tapestry of linguistic, cultural, and historical threads that have shaped this excellent script directing the flow of history in our world by the magnificent lines of destiny.</p>

<h2 id="origins-of-the-arabic-alphabet">Origins of the Arabic Alphabet</h2>

<p>The long winding story of the Arabic alphabet begins with its ancient predecessors, the Nabataean and Aramaic scripts. The Arabic script originated from the Nabataean script, a writing system developed by the Nabataean people, a nomadic Arab tribe that inhabited the region of modern-day Jordan, Palestine, and the Sinai Peninsula around the 2nd Century BCE. The Nabataean script, in turn, descended from the Aramaic script, one of the dominant writing systems in the ancient Near East, spanning from modern-day Iraq to the Levant.</p>

<p>The Arabic alphabet as we know it today emerged in the late 4th to early 5th centuries CE, during the rise of the Arab tribes and the formation of the Arabic language. Like other languages, the script evolved over time, adapting to the needs of the language and the cultural influences of the different regions where it was used. But it was only in the 7th Century that the Qur’an would immortalize its position and status as it became the primary script for writing the Qur’an, the holy book of Islam. The Islamic conquests during the 7th and 8th centuries CE further solidified and expanded the reach of the Arabic alphabet. This led to the script’s rapid expansion across the vast Islamic empire, from Spain to India, and its adoption by numerous languages and cultures.</p>

<h2 id="distinct-structure-of-the-arabic-alphabet">Distinct Structure of the Arabic Alphabet</h2>

<p><img src="assets/images/posts/wa-ma-tawfeeq_resized.webp" alt="The distinctive style and structure of the Arabic Alphabet" /></p>
<p style="text-align: center;">Source: <a href="https://quran.com/11:88" tagret="_blank">The Glorious Qur'an 11:88</a></p>

<p>The Arabic alphabet is a prominent writing system distinguished by its unique structure and design. Among its most notable features is its abjad nature, meaning it primarily represents consonants, with vowels often omitted or marked by diacritical signs. This characteristic allows for a certain fluidity and flexibility in the script, as readers rely on context and diacritic knowledge to determine the appropriate vowels.</p>

<p>In contrast to English, the Arabic script is written from right to left, consisting of 28 letters, all consonants. Unlike many writing systems, Arabic letters are connected, forming a flowing cursive style that varies depending on the letter’s position within a word. The script has four forms for each letter: an isolated, initial, medial, and final part. This unique feature creates an elegant and harmonious appearance; as each letter seamlessly merges with its neighbors, the script appears like a flowing river branching into tributaries.</p>

<p>In the Arabic alphabet, the presence of diacritical marks is known as “tashkeel” or “harakat”. These signs indicate short vowels, consonant doubling, and other phonetic features not inherently represented by the abjad system. While diacritical marks are not always used in everyday writing, they play a crucial role in the Qur’an, religious texts, poetry, and other contexts where precise pronunciation and understanding are indispensable.</p>

<h2 id="the-beauty-of-the-arabic-alphabet">The Beauty of the Arabic Alphabet</h2>

<p>The beauty of the Arabic alphabet doesn’t owe itself due to the distinctive structure but also to the artistry and creativity it has inspired throughout history. Arabic Calligraphy, the art of beautiful handwriting, has long been a revered art form in the Islamic world. Qur’an, the central religious text of Islam, is considered the ultimate source of beauty in the Arabic language, and its verses have been meticulously transcribed, illuminated, and adorned by generation after generation of calligraphers.</p>

<p>The Arabic script’s graceful, interconnected nature perfectly lends to calligraphic expression. Each letter, with its elegant curves and varying forms, is skillfully manipulated and combined to create intricate compositions that are both visually captivating and profoundly meaningful. In addition, the flexibility of the script allows for a vast range of artistic styles of expression, from the bold and geometric Kufic script to the delicate and fluid Naskh and Thuluth styles.</p>

<p>The Arabic alphabet’s beauty transcends the realm of calligraphy and permeates various aspects of Islamic art and architecture. Depiction of human and animal figures is often discouraged in Islamic culture and religious contexts. The Arabic script has become a prominent decorative element, adorning mosques, palaces, and other monuments with its graceful lines and spiritual messages. In addition, the script’s inherent harmony and proportion make it a perfect choice for ornamental designs, as it seamlessly blends with other geometric and floral motifs.</p>

<p>The Arabic alphabet has also played a significant role in preserving and disseminating knowledge throughout history. From the House of Wisdom in Baghdad to the great libraries of Cordoba and Cairo, the Arabic script has been used to record and transmit scientific, philosophical, and literary works, contributing to countless societies’ intellectual and cultural development. The Arabic alphabet played an instrumental role in ending the European dark ages and heralding a new era of scientific growth and discovery. This rich tradition of learning and scholarship has further enhanced the beauty and prestige of the Arabic alphabet, as it became the vehicle for expressing human thought and creativity.</p>

<h2 id="the-magic-of-arabic-root-words-the-heart-of-language-and-meaning">The Magic of Arabic Root Words: The Heart of Language and Meaning</h2>

<p>At the core of the Arabic language lies a unique and fascinating system that gives life to its words and enables its speakers to convey diverse meanings with elegance and precision. This system is rooted in the concept of triliteral roots, which act as the building blocks for the majority of Arabic words. By understanding the intricacies of Arabic root words, we can delve deeper into the structure of the language and appreciate the linguistic artistry that sets it apart from many other languages.</p>

<h3 id="the-power-of-three-triliteral-roots-and-their-significance">The Power of Three: Triliteral Roots and Their Significance</h3>

<p>Arabic is primarily based on triliteral roots, consisting of three consonants with a core meaning. These roots act as the foundation for creating different words by adding various prefixes, suffixes, and infixes and altering the vowels between the consonants. Through derivation, Arabic can generate a vast array of related words that revolve around a central theme, making the language remarkably concise and expressive.</p>

<p>For instance, consider the root (ك-ت-ب) ‘k-t-b’, which revolves around the concept of writing. From this simple root, we can derive numerous words, such as ‘كتاب’ (book), ‘كاتب’ (writer), ‘مكتب’ (office or desk), ‘مكتوب’ (written or destined), and ‘كتب’ (books), among others. By changing the vowels and adding prefixes or suffixes, the Arabic language can convey various shades of meaning connected to the essence of writing.</p>

<h3 id="the-art-of-derivation-unlocking-the-beauty-of-arabic-root-words">The Art of Derivation: Unlocking the Beauty of Arabic Root Words</h3>

<p><img src="assets/images/posts/salaman-qawlun_resized.webp" alt="All Arabic words can be traced back to a root word" /></p>
<p style="text-align: center;">Source: <a href="https://quran.com/36:58" tagret="_blank">The Glorious Qur'an 36:58</a></p>

<p>The process of deriving words from roots in Arabic is nothing short of a linguistic dance, where each step adds nuance and depth to the original meaning. This art of derivation is governed by a system of patterns or templates, known as ‘wazn’ (plural ‘awzan’), which dictate the structure of the derived words. By applying these patterns to a given root, Arabic speakers can create many related words, each carrying a distinct yet related meaning with reference to the root word.</p>

<p>For example, the root (د-ر-س) ‘d-r-s’, associated with learning and teaching, can be used to form words like ‘درس’ (lesson), ‘مدرسة’ (school), ‘مدرس’ (teacher), ‘تدريس’ (teaching), and ‘إدراك’ (comprehension). The relationship between these words is apparent, and their connection to the central theme of learning and teaching is evident, showcasing the power and flexibility of the Arabic root system.</p>

<p>This unique derivation system also serves a mnemonic function, allowing Arabic speakers to recognize and recall related words more easily, thanks to their shared roots and patterns. The interconnectedness of words in the Arabic language is a testament to its beauty and depth and a reflection of the importance of unity and harmony in the Arabic culture and Weltanschauung.</p>

<h3 id="the-poetry-of-roots-arabic-root-words-in-literature-and-everyday-life">The Poetry of Roots: Arabic Root Words in Literature and Everyday Life</h3>

<p>The beauty and versatility of Arabic root words are not confined to linguistics but permeate various aspects of Arabic culture, particularly its rich tradition of poetry and literature. Classical and modern Arabic poets have long employed the sophisticated root system to weave intricate tapestries of meaning, embellishing momentous words and deeds. Thereby evoking vivid imagery and emotions through skillful words derived from shared roots.</p>

<p>In everyday conversations, Arabic speakers intuitively harness the power of root words to express themselves eloquently and concisely. The ability to create and comprehend a vast array of meanings from a single root is a testament to the depth and sophistication of the Arabic language and the intellect of its speakers.</p>

<h2 id="the-timeless-beauty-and-influence-of-the-arabic-alphabet">The Timeless Beauty and Influence of the Arabic Alphabet</h2>

<p>The Arabic alphabet’s timeless beauty and elegance have captivated the hearts and dazzled the minds of people from diverse cultures and backgrounds for centuries. Its unique structure and fluidity have allowed it to adapt and thrive in various contexts, from the sacred realm of religious texts to acting as a repository for scientific knowledge to the creative world of calligraphy and art.</p>

<p>Today, the Arabic alphabet continues to inspire and enchant millions of people around the globe. Its lasting appeal is a testament to the script’s intrinsic beauty, versatility, and the rich cultural heritage it embodies. As we reflect on the origins, structure, and legacy of the Arabic alphabet, we are reminded of the profound connections that bind us across time, space, and language and of the enduring power of art and writing to elevate the human experience.</p>

<h2 id="the-glorious-quran">The Glorious Qur’an</h2>

<p>The Qur’an possesses an unmatched, timeless beauty that transcends language and culture. As a cornerstone of the Islamic faith, it stands witness to divine perfection and unity, conveying profound spiritual truths with extraordinary elegance. Written in Classical Arabic, the Qur’an possesses a unique linguistic structure and stylistic beauty and is considered the enduring miracle of Islam. The verses are rhythmic, the language is expressive, and the literary style is ethereal, embodying linguistic artistry that has moved the hearts of millions across time and space.</p>

<p>The depth and richness of the Arabic language used in the Qur’an contribute significantly to its timeless beauty. Each word and verse is filled with multiple layers of meaning, capturing nuances often lost in translation. This linguistic complexity creates a conversational, contemplative experience that engages the intellect and emotions, facilitating a deeper understanding of spiritual truths. Furthermore, when recited, the sounds of the Arabic language add another layer of aesthetic appeal, resonating with listeners and encouraging listeners to reflect and ponder on the phenomena of our world and the universe. Thus, with its lyrical verses and profound wisdom, the Qur’an continues to inspire and illuminate the hearts of billions worldwide.</p>

<h2 id="conclusion">Conclusion</h2>

<p>The Arabic alphabet is a peerless script with a rich history, unique structure, and enduring beauty. From its origins in the Nabataean and Aramaic scripts to its widespread use in the Islamic world, the Arabic alphabet has evolved and adapted to the needs of its speakers and the diverse cultures that have adopted it. The timeless beauty of the Arabic script, as seen in the art of calligraphy and its influence on Islamic art and architecture and the broader world, is a testament to its enduring appeal and versatility. While exploring the fascinating world of the Arabic alphabet, we discover a complex tapestry of linguistic, cultural, and historical threads that weave together to create an awe- and artistically-inspiring writing system.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Writings" /><summary type="html"><![CDATA[The Arabic alphabet is a fascinating script with a rich history and a unique structure that has captivated scholars, artists, and linguists for centuries. Long has Arabic enchanted people with the ebb and flow of its peerless scripts adorning books, walls, and even hearts.]]></summary></entry><entry><title type="html">Building a Messaging System with NATS, Python, and Azure Kubernetes Service</title><link href="https://www.faizanbashir.me/building-a-messaging-system-with-nats-python-and-azure-kubernetes-service" rel="alternate" type="text/html" title="Building a Messaging System with NATS, Python, and Azure Kubernetes Service" /><published>2023-06-16T10:00:00+00:00</published><updated>2023-06-16T10:00:00+00:00</updated><id>https://www.faizanbashir.me/building-a-messaging-system-with-nats-python-and-azure-kubernetes-service</id><content type="html" xml:base="https://www.faizanbashir.me/building-a-messaging-system-with-nats-python-and-azure-kubernetes-service"><![CDATA[<h1 id="building-a-messaging-system-with-nats-python-and-azure-kubernetes-service">Building a Messaging System with NATS, Python, and Azure Kubernetes Service</h1>

<p>This article walks you through building a messaging system with NATS (an acronym for Neural Autonomic Transport System) and Python deployed in Azure Kubernetes Service (AKS). NATS is an open-source messaging system. NATS has a core publish-subscribe server designed for performance, scalability, and ease of use.</p>

<h1 id="prerequisites">Prerequisites</h1>

<p>Before we start, make sure you have the following:</p>

<ul>
  <li>An active Azure subscription.</li>
  <li>The Azure CLI <code class="language-plaintext highlighter-rouge">az</code> installed and configured.</li>
  <li>Python 3 and pip installed.</li>
  <li>Docker installed.</li>
  <li>Kubernetes CLI <code class="language-plaintext highlighter-rouge">kubectl</code> installed and configured.</li>
  <li>Helm: We’ll use Helm to deploy NATS on our Kubernetes cluster.</li>
</ul>

<hr />

<h1 id="table-of-contents">Table of Contents</h1>
<ul>
  <li><a href="#deploying-nats-on-azure-kubernetes-service">Deploying NATS on Azure Kubernetes Service</a></li>
  <li><a href="#creating-a-python-publisher-and-subscriber">Creating a Python Publisher and Subscriber</a></li>
  <li><a href="#running-the-python-applications-in-kubernetes">Running the Python Applications in Kubernetes</a></li>
  <li><a href="#deploying-to-kubernetes-and-testing">Deploying to Kubernetes and Testing</a></li>
  <li><a href="#conclusion">Conclusion</a></li>
</ul>

<hr />

<h2 id="deploying-nats-on-azure-kubernetes-service">Deploying NATS on Azure Kubernetes Service</h2>

<p>First, we need to create a Kubernetes cluster on AKS. Use the following <code class="language-plaintext highlighter-rouge">az</code> CLI commands:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">az group create <span class="nt">--name</span> myResourceGroup <span class="nt">--location</span> eastus
az aks create <span class="nt">--resource-group</span> myResourceGroup <span class="nt">--name</span> myAKSCluster <span class="nt">--node-count</span> 3 <span class="nt">--enable-addons</span> monitoring <span class="nt">--generate-ssh-keys</span>
az aks get-credentials <span class="nt">--resource-group</span> myResourceGroup <span class="nt">--name</span> myAKSCluster</code></pre></figure>

<p>Next, we’ll deploy a NATS server on our AKS cluster. We can do this easily using Helm, a package manager for Kubernetes. With Helm installed and your, AKS cluster up and running, execute the following commands to add the NATS Helm chart repo and install NATS:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">helm repo add nats https://nats-io.github.io/k8s/helm/charts/
helm repo update
helm <span class="nb">install </span>my-nats nats/nats</code></pre></figure>

<p>The above command deploys a single server NATS setup onto your cluster.</p>

<h2 id="creating-a-python-publisher-and-subscriber">Creating a Python Publisher and Subscriber</h2>

<p>Next, we’ll create a publisher and a subscriber application using Python. The publisher will publish messages to a NATS subject, and the subscriber will subscribe to this subject to receive these messages. Here’s a simple example of a publisher in the <code class="language-plaintext highlighter-rouge">publisher.py</code> file:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">nats</span> <span class="kn">import</span> <span class="n">NATS</span><span class="p">,</span> <span class="n">Msg</span>

<span class="k">async</span> <span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
    <span class="n">nc</span> <span class="o">=</span> <span class="n">NATS</span><span class="p">()</span>
    <span class="k">await</span> <span class="n">nc</span><span class="p">.</span><span class="n">connect</span><span class="p">(</span><span class="s">"nats://localhost:4222"</span><span class="p">)</span>
    <span class="k">await</span> <span class="n">nc</span><span class="p">.</span><span class="n">publish</span><span class="p">(</span><span class="s">"foo"</span><span class="p">,</span> <span class="sa">b</span><span class="s">'Hello World'</span><span class="p">)</span>
    <span class="k">await</span> <span class="n">nc</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>

<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span>
    <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="p">.</span><span class="n">get_event_loop</span><span class="p">()</span>
    <span class="n">loop</span><span class="p">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">main</span><span class="p">())</span>
    <span class="n">loop</span><span class="p">.</span><span class="n">close</span><span class="p">()</span></code></pre></figure>

<p>And here’s a Python subscriber <code class="language-plaintext highlighter-rouge">subscriber.py</code>:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">nats</span> <span class="kn">import</span> <span class="n">NATS</span><span class="p">,</span> <span class="n">Msg</span>

<span class="k">async</span> <span class="k">def</span> <span class="nf">message_handler</span><span class="p">(</span><span class="n">msg</span><span class="p">:</span> <span class="n">Msg</span><span class="p">):</span>
    <span class="n">subject</span> <span class="o">=</span> <span class="n">msg</span><span class="p">.</span><span class="n">subject</span>
    <span class="n">reply</span> <span class="o">=</span> <span class="n">msg</span><span class="p">.</span><span class="n">reply</span>
    <span class="n">data</span> <span class="o">=</span> <span class="n">msg</span><span class="p">.</span><span class="n">data</span><span class="p">.</span><span class="n">decode</span><span class="p">()</span>
    <span class="k">print</span><span class="p">(</span><span class="sa">f</span><span class="s">'Received a message on </span><span class="si">{</span><span class="n">subject</span><span class="si">}</span><span class="s">: </span><span class="si">{</span><span class="n">data</span><span class="si">}</span><span class="s">'</span><span class="p">)</span>

<span class="k">async</span> <span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
    <span class="n">nc</span> <span class="o">=</span> <span class="n">NATS</span><span class="p">()</span>
    <span class="k">await</span> <span class="n">nc</span><span class="p">.</span><span class="n">connect</span><span class="p">(</span><span class="s">"nats://localhost:4222"</span><span class="p">)</span>
    <span class="n">sid</span> <span class="o">=</span> <span class="k">await</span> <span class="n">nc</span><span class="p">.</span><span class="n">subscribe</span><span class="p">(</span><span class="s">"foo"</span><span class="p">,</span> <span class="n">cb</span><span class="o">=</span><span class="n">message_handler</span><span class="p">)</span>
    <span class="k">await</span> <span class="n">nc</span><span class="p">.</span><span class="n">auto_unsubscribe</span><span class="p">(</span><span class="n">sid</span><span class="p">,</span> <span class="nb">max</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">await</span> <span class="n">nc</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>

<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span>
    <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="p">.</span><span class="n">get_event_loop</span><span class="p">()</span>
    <span class="n">loop</span><span class="p">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">main</span><span class="p">())</span>
    <span class="n">loop</span><span class="p">.</span><span class="n">close</span><span class="p">()</span></code></pre></figure>

<p>These scripts will send and receive a “Hello World” message through NATS.</p>

<h2 id="running-the-python-applications-in-kubernetes">Running the Python Applications in Kubernetes</h2>

<p>Package your Python applications as Docker containers and deploy them onto your AKS cluster. Here are basic <code class="language-plaintext highlighter-rouge">Dockerfile</code> examples for both applications:</p>

<p>Dockefile for Publisher:</p>

<figure class="highlight"><pre><code class="language-dockerfile" data-lang="dockerfile"><span class="k">FROM</span><span class="s"> python:3.7-slim</span>
<span class="k">WORKDIR</span><span class="s"> /app</span>
<span class="k">COPY</span><span class="s"> . /app</span>
<span class="k">RUN </span>pip <span class="nb">install </span>nats.py
<span class="k">CMD</span><span class="s"> [ "python", "./publisher.py" ]</span></code></pre></figure>

<p>Dockerfile for Subscriber:</p>

<figure class="highlight"><pre><code class="language-dockerfile" data-lang="dockerfile"><span class="k">FROM</span><span class="s"> python:3.7-slim</span>
<span class="k">WORKDIR</span><span class="s"> /app</span>
<span class="k">COPY</span><span class="s"> . /app</span>
<span class="k">RUN </span>pip <span class="nb">install </span>nats.py
<span class="k">CMD</span><span class="s"> [ "python", "./subscriber.py" ]</span></code></pre></figure>

<p>Then, build and push these Docker images to a Docker registry accessible by your AKS cluster.</p>

<h2 id="deploying-to-kubernetes-and-testing">Deploying to Kubernetes and Testing</h2>

<p>After preparing the Docker images, we can deploy our Python applications to our AKS cluster. We’ll use Kubernetes Deployments and Services to manage our applications. Here are basic examples for the publisher and subscriber:</p>

<p>Kubernetes Publisher Deployment Spec:</p>

<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="na">apiVersion</span><span class="pi">:</span> <span class="s">apps/v1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Deployment</span>
<span class="na">metadata</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">publisher-deployment</span>
<span class="na">spec</span><span class="pi">:</span>
  <span class="na">replicas</span><span class="pi">:</span> <span class="m">1</span>
  <span class="na">selector</span><span class="pi">:</span>
    <span class="na">matchLabels</span><span class="pi">:</span>
      <span class="na">app</span><span class="pi">:</span> <span class="s">publisher</span>
  <span class="na">template</span><span class="pi">:</span>
    <span class="na">metadata</span><span class="pi">:</span>
      <span class="na">labels</span><span class="pi">:</span>
        <span class="na">app</span><span class="pi">:</span> <span class="s">publisher</span>
    <span class="na">spec</span><span class="pi">:</span>
      <span class="na">containers</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">publisher</span>
        <span class="na">image</span><span class="pi">:</span> <span class="s">&lt;your-docker-registry&gt;/publisher:latest</span>
        <span class="na">ports</span><span class="pi">:</span>
        <span class="pi">-</span> <span class="na">containerPort</span><span class="pi">:</span> <span class="s">8080</span></code></pre></figure>

<p>Kubernetes Subscriber Deployment Spec:</p>

<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="na">apiVersion</span><span class="pi">:</span> <span class="s">apps/v1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Deployment</span>
<span class="na">metadata</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">subscriber-deployment</span>
<span class="na">spec</span><span class="pi">:</span>
  <span class="na">replicas</span><span class="pi">:</span> <span class="m">1</span>
  <span class="na">selector</span><span class="pi">:</span>
    <span class="na">matchLabels</span><span class="pi">:</span>
      <span class="na">app</span><span class="pi">:</span> <span class="s">subscriber</span>
  <span class="na">template</span><span class="pi">:</span>
    <span class="na">metadata</span><span class="pi">:</span>
      <span class="na">labels</span><span class="pi">:</span>
        <span class="na">app</span><span class="pi">:</span> <span class="s">subscriber</span>
    <span class="na">spec</span><span class="pi">:</span>
      <span class="na">containers</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">subscriber</span>
        <span class="na">image</span><span class="pi">:</span> <span class="s">&lt;your-docker-registry&gt;/subscriber:latest</span>
        <span class="na">ports</span><span class="pi">:</span>
        <span class="pi">-</span> <span class="na">containerPort</span><span class="pi">:</span> <span class="s">8080</span></code></pre></figure>

<p>Deploy these Kubernetes objects using <code class="language-plaintext highlighter-rouge">kubectl apply -f &lt;file-name&gt;</code>. Once the Deployments and Services are active, the publisher will send messages, and the subscriber will receive them.</p>

<p>To verify that our system is working correctly, we can check the logs of our subscriber:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">kubectl logs <span class="nt">-l</span> <span class="nv">app</span><span class="o">=</span>subscriber</code></pre></figure>

<p>If everything is set up correctly, you should see <code class="language-plaintext highlighter-rouge">"Received a message on foo: Hello World"</code> in the logs.</p>

<h2 id="conclusion">Conclusion</h2>

<p>In this guide, we built a distributed messaging system using NATS, Python, and Azure Kubernetes Service. We deployed a NATS server onto AKS, made Python publisher and subscriber applications, packaged them as Docker containers, and ran them on AKS.</p>

<p>This guide is a basic introduction to NATS, Python, and AKS. Feel free to expand upon this guide to build more complex systems tailored to your needs.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Python" /><category term="Kubernetes" /><category term="Azure" /><summary type="html"><![CDATA[Learn how to build a messaging system using NATS, Python, and Azure Kubernetes Service in our step-by-step guide.]]></summary></entry><entry><title type="html">Event-Driven Scaling of Python Applications in Azure Kubernetes Service (AKS) using KEDA</title><link href="https://www.faizanbashir.me/event-driven-scaling-of-python-applications-in-azure-kubernetes-service-aks-using-keda" rel="alternate" type="text/html" title="Event-Driven Scaling of Python Applications in Azure Kubernetes Service (AKS) using KEDA" /><published>2023-06-15T10:00:00+00:00</published><updated>2023-06-15T10:00:00+00:00</updated><id>https://www.faizanbashir.me/event-driven-scaling-of-python-applications-in-azure-kubernetes-service-aks-using-keda</id><content type="html" xml:base="https://www.faizanbashir.me/event-driven-scaling-of-python-applications-in-azure-kubernetes-service-aks-using-keda"><![CDATA[<h1 id="event-driven-scaling-of-python-applications-in-azure-kubernetes-service-aks-using-keda">Event-Driven Scaling of Python Applications in Azure Kubernetes Service (AKS) using KEDA</h1>

<p>In this article, we will walk you through setting up event-driven scaling of a Python application deployed in Azure Kubernetes Service (AKS) using Kubernetes-based Event-Driven Autoscaling (KEDA). KEDA is an open-source project that provides event-driven autoscaling for Kubernetes workloads.</p>

<h1 id="prerequisites">Prerequisites</h1>

<p>Before we start, ensure you have the following installed on your local machine:</p>

<ul>
  <li>Python: We’ll use Python to write our application.</li>
  <li>Docker: We’ll use Docker to build and package our Python application.</li>
  <li>Kubernetes CLI <code class="language-plaintext highlighter-rouge">kubectl</code>: We’ll use kubectl to interact with our Kubernetes cluster.</li>
  <li>Helm: We’ll use Helm to deploy KEDA on our Kubernetes cluster.</li>
</ul>

<p>You’ll also need an AKS cluster for deploying our application and KEDA. If you don’t have one, you can create an AKS cluster by following this <a href="https://docs.microsoft.com/en-us/azure/aks/intro-kubernetes">Azure documentation</a>.</p>

<hr />

<h1 id="table-of-contents">Table of Contents:</h1>

<ul>
  <li><a href="#deploying-keda-on-aks">Deploying KEDA on AKS</a></li>
  <li><a href="#building-a-python-application-for-event-driven-scaling">Building a Python Application for Event-Driven Scaling</a></li>
  <li><a href="#packaging-and-deploying-python-application-in-aks">Packaging and Deploying Python Application in AKS</a></li>
  <li><a href="#testing-event-driven-scaling">Testing Event-Driven Scaling</a></li>
  <li><a href="#conclusion">Conclusion</a></li>
</ul>

<hr />

<h2 id="deploying-keda-on-aks">Deploying KEDA on AKS</h2>

<p>We’ll use Helm, a Kubernetes package manager, to deploy KEDA on AKS. Execute the following commands to add the KEDA Helm chart repository and install KEDA:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">helm repo add kedacore https://kedacore.github.io/charts
helm repo update
kubectl create namespace keda
helm <span class="nb">install </span>keda kedacore/keda <span class="nt">--namespace</span> keda</code></pre></figure>

<h2 id="building-a-python-application-for-event-driven-scaling">Building a Python Application for Event-Driven Scaling</h2>

<p>We will create a simple Python application that reads messages from an Azure Storage Queue. This application will serve as our example for event-driven scaling. The number of pods of this application will scale up and down based on the number of messages in the Azure Storage Queue. Here’s a simple Python script that reads messages from Azure Storage Queue:</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">azure.storage.queue</span> <span class="kn">import</span> <span class="n">QueueService</span>
<span class="kn">import</span> <span class="nn">os</span>

<span class="n">queue_service</span> <span class="o">=</span> <span class="n">QueueService</span><span class="p">(</span><span class="n">account_name</span><span class="o">=</span><span class="n">os</span><span class="p">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">"AZURE_STORAGE_ACCOUNT"</span><span class="p">),</span> <span class="n">account_key</span><span class="o">=</span><span class="n">os</span><span class="p">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">"AZURE_STORAGE_ACCESS_KEY"</span><span class="p">))</span>
<span class="n">queue_name</span> <span class="o">=</span> <span class="n">os</span><span class="p">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">"QUEUE_NAME"</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">read_messages</span><span class="p">():</span>
    <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
        <span class="n">messages</span> <span class="o">=</span> <span class="n">queue_service</span><span class="p">.</span><span class="n">get_messages</span><span class="p">(</span><span class="n">queue_name</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">messages</span><span class="p">:</span>
            <span class="k">print</span><span class="p">(</span><span class="sa">f</span><span class="s">"Processing message: </span><span class="si">{</span><span class="n">message</span><span class="p">.</span><span class="n">content</span><span class="si">}</span><span class="s">"</span><span class="p">)</span>
            <span class="n">queue_service</span><span class="p">.</span><span class="n">delete_message</span><span class="p">(</span><span class="n">queue_name</span><span class="p">,</span> <span class="n">message</span><span class="p">.</span><span class="nb">id</span><span class="p">,</span> <span class="n">message</span><span class="p">.</span><span class="n">pop_receipt</span><span class="p">)</span>

<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span>
    <span class="n">read_messages</span><span class="p">()</span></code></pre></figure>

<h2 id="packaging-and-deploying-python-application-in-aks">Packaging and Deploying Python Application in AKS</h2>

<p>Now, we will package our Python application using Docker. We need to create a Dockerfile:</p>

<figure class="highlight"><pre><code class="language-dockerfile" data-lang="dockerfile"><span class="k">FROM</span><span class="s"> python:3.7</span>

<span class="k">WORKDIR</span><span class="s"> /app</span>

<span class="k">COPY</span><span class="s"> requirements.txt ./</span>
<span class="k">RUN </span>pip <span class="nb">install</span> <span class="nt">--no-cache-dir</span> <span class="nt">-r</span> requirements.txt

<span class="k">COPY</span><span class="s"> . .</span>

<span class="k">CMD</span><span class="s"> [ "python", "./app.py" ]</span></code></pre></figure>

<p>After building the Docker image and pushing it to a Docker registry, we create a Kubernetes deployment for our application. However, to enable KEDA, we need to create a <code class="language-plaintext highlighter-rouge">ScaledObject</code> which defines the scaling parameters:</p>

<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="na">apiVersion</span><span class="pi">:</span> <span class="s">keda.sh/v1alpha1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">ScaledObject</span>
<span class="na">metadata</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">python-app-scaledobject</span>
  <span class="na">namespace</span><span class="pi">:</span> <span class="s">default</span>
<span class="na">spec</span><span class="pi">:</span>
  <span class="na">scaleTargetRef</span><span class="pi">:</span>
    <span class="na">name</span><span class="pi">:</span> <span class="s">python-app</span>
  <span class="na">minReplicaCount</span><span class="pi">:</span> <span class="m">0</span>
  <span class="na">maxReplicaCount</span><span class="pi">:</span> <span class="m">100</span>
  <span class="na">triggers</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="na">type</span><span class="pi">:</span> <span class="s">azure-queue</span>
    <span class="na">metadata</span><span class="pi">:</span>
      <span class="na">queueName</span><span class="pi">:</span> <span class="s">myqueue</span>
      <span class="na">queueLength</span><span class="pi">:</span> <span class="s1">'</span><span class="s">5'</span>
      <span class="na">connectionFromEnv</span><span class="pi">:</span> <span class="s">AzureWebJobsStorage</span></code></pre></figure>

<h2 id="testing-event-driven-scaling">Testing Event-Driven Scaling</h2>

<p>To test the event-driven scaling, add messages to the Azure Storage Queue and observe the number of pods of your Python application. You should see more pods when there are more messages in the queue and fewer pods when there are fewer messages.</p>

<h2 id="conclusion">Conclusion</h2>

<p>This article walked you through setting up event-driven scaling of a Python application in Azure Kubernetes Service using Kubernetes-based Event-Driven Autoscaling (KEDA). This capability is crucial in building highly scalable and responsive applications that automatically adjust their resources based on demand.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Python" /><category term="Kubernetes" /><category term="Azure" /><summary type="html"><![CDATA[Learn how to set up event-driven scaling of Python applications in Azure Kubernetes Service using KEDA, an open-source project providing event-driven autoscaling for Kubernetes workloads.]]></summary></entry><entry><title type="html">Migrating Legacy Python Applications to Azure Kubernetes Service AKS</title><link href="https://www.faizanbashir.me/migrating-legacy-python-applications-to-azure-kubernetes-service-aks" rel="alternate" type="text/html" title="Migrating Legacy Python Applications to Azure Kubernetes Service AKS" /><published>2023-06-13T10:00:00+00:00</published><updated>2023-06-13T10:00:00+00:00</updated><id>https://www.faizanbashir.me/migrating-legacy-python-applications-to-azure-kubernetes-service-aks</id><content type="html" xml:base="https://www.faizanbashir.me/migrating-legacy-python-applications-to-azure-kubernetes-service-aks"><![CDATA[<h1 id="migrating-legacy-python-applications-to-kubernetes-on-azure-a-step-by-step-guide">Migrating Legacy Python Applications to Kubernetes on Azure: A Step-by-Step Guide</h1>

<p>Kubernetes, also known as K8s, is an open-source Container Orchestration platform, it manages the life-cycle of containerized applications effectively and efficiently, including deploying and scaling, and it’s one of the essential tools for digital transformation and cloud-native development. This article will guide you through migrating a legacy Python application to a Kubernetes cluster on Azure.</p>

<h1 id="prerequisites">Prerequisites</h1>

<p>Before you begin, you need to have:</p>

<ol>
  <li>A Microsoft Azure account with an active subscription</li>
  <li>The Azure <code class="language-plaintext highlighter-rouge">az</code> CLI installed on your local machine</li>
  <li>Docker installed on your local machine</li>
  <li>Kubernetes CLI <code class="language-plaintext highlighter-rouge">kubectl</code> installed on your local machine</li>
  <li>A Python application you want to migrate</li>
</ol>

<hr />
<h1 id="table-of-contents">Table of Contents</h1>

<ul>
  <li><a href="#preparing-your-application">Preparing Your Application</a></li>
  <li><a href="#packaging-your-application-in-a-docker-container">Packaging Your Application in a Docker Container</a></li>
  <li><a href="#setting-up-an-azure-kubernetes-service-aks">Setting Up an Azure Kubernetes Service (AKS)</a></li>
  <li><a href="#deploying-your-application-to-aks">Deploying Your Application to AKS</a></li>
  <li><a href="#testing-your-deployment">Testing Your Deployment</a></li>
  <li><a href="#conclusion">Conclusion</a></li>
</ul>

<hr />

<h2 id="preparing-your-application">Preparing Your Application</h2>

<p>Firstly, ensure your Python application is designed to work with a 12-factor application methodology. Some of the key factors include:</p>

<ul>
  <li><strong>Codebase</strong>: Maintain a single codebase for your application, and use version control systems(VCS) like Git to track changes.</li>
  <li><strong>Dependencies</strong>: Use package managers and dependency management tools to manage your application’s dependencies.</li>
  <li><strong>Config</strong>: Use Kubernetes ConfigMaps and Secrets to store configuration data, such as environment variables and sensitive information.</li>
  <li><strong>Backing services</strong>: Kubernetes makes connecting your application to backing services like databases, message queues, and caching systems easy through Services and Ingress resources.</li>
</ul>

<p><a href="/implementing-12-factor-app-principles-with-kubernetes">Check out this guide to learn more about implementing the 12-factor application methodology using Kubernetes.</a></p>

<h2 id="packaging-your-application-in-a-docker-container">Packaging Your Application in a Docker Container</h2>
<p>For Kubernetes to manage your application, it needs to be containerized. We will use Docker to achieve this. Here’s a simple Dockerfile example for a Python application:</p>

<figure class="highlight"><pre><code class="language-dockerfile" data-lang="dockerfile"><span class="c"># Use an official Python runtime as a parent image</span>
<span class="k">FROM</span><span class="s"> python:3.7-slim</span>

<span class="c"># Set the working directory in the container</span>
<span class="k">WORKDIR</span><span class="s"> /app</span>

<span class="c"># Add the current directory code to the working directory</span>
<span class="k">ADD</span><span class="s"> . /app</span>

<span class="c"># Install the packages mentioned in the requirements.txt</span>
<span class="k">RUN </span>pip <span class="nb">install</span> <span class="nt">--trusted-host</span> pypi.python.org <span class="nt">-r</span> requirements.txt

<span class="c"># Expose port 80</span>
<span class="k">EXPOSE</span><span class="s"> 80</span>

<span class="c"># Run app.py when the container launches</span>
<span class="k">CMD</span><span class="s"> ["python", "app.py"]</span></code></pre></figure>

<p>Use the following command to build your Docker image:</p>

<figure class="highlight"><pre><code class="language-shell" data-lang="shell">docker build <span class="nt">-t</span> my-python-app .</code></pre></figure>

<h2 id="setting-up-an-azure-kubernetes-service-aks">Setting Up an Azure Kubernetes Service (AKS)</h2>

<p>Now that you have a Docker container let’s set up AKS. Use the Azure CLI to create a resource group:</p>

<figure class="highlight"><pre><code class="language-shell" data-lang="shell">az group create <span class="nt">--name</span> myResourceGroup <span class="nt">--location</span> eastus</code></pre></figure>

<p>Create AKS cluster:</p>

<figure class="highlight"><pre><code class="language-shell" data-lang="shell">az aks create <span class="nt">--resource-group</span> myResourceGroup <span class="nt">--name</span> myAKSCluster <span class="nt">--node-count</span> 1 <span class="nt">--enable-addons</span> monitoring <span class="nt">--generate-ssh-keys</span></code></pre></figure>

<h2 id="deploying-your-application-to-aks">Deploying Your Application to AKS</h2>

<p>To deploy your Python app, create a Kubernetes deployment configuration. The configuration specifies how to create/update instances of your application. Here is a simple deployment configuration:</p>

<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="na">apiVersion</span><span class="pi">:</span> <span class="s">apps/v1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Deployment</span>
<span class="na">metadata</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">my-python-app</span>
<span class="na">spec</span><span class="pi">:</span>
  <span class="na">replicas</span><span class="pi">:</span> <span class="m">3</span>
  <span class="na">selector</span><span class="pi">:</span>
    <span class="na">matchLabels</span><span class="pi">:</span>
      <span class="na">app</span><span class="pi">:</span> <span class="s">my-python-app</span>
  <span class="na">template</span><span class="pi">:</span>
    <span class="na">metadata</span><span class="pi">:</span>
      <span class="na">labels</span><span class="pi">:</span>
        <span class="na">app</span><span class="pi">:</span> <span class="s">my-python-app</span>
    <span class="na">spec</span><span class="pi">:</span>
      <span class="na">containers</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">my-python-app</span>
        <span class="na">image</span><span class="pi">:</span> <span class="s">&lt;your-dockerhub-username&gt;/my-python-app:v1</span>
        <span class="na">ports</span><span class="pi">:</span>
        <span class="pi">-</span> <span class="na">containerPort</span><span class="pi">:</span> <span class="s">80</span></code></pre></figure>

<p>Deploy your application using the <code class="language-plaintext highlighter-rouge">kubectl</code> command:</p>

<figure class="highlight"><pre><code class="language-shell" data-lang="shell">kubectl apply <span class="nt">-f</span> my-python-app-deployment.yaml</code></pre></figure>

<h2 id="testing-your-deployment">Testing Your Deployment</h2>
<p>Now that your application is running on Kubernetes, you can interact with the Kubernetes cluster by using the <code class="language-plaintext highlighter-rouge">kubectl</code> command line tool:</p>

<figure class="highlight"><pre><code class="language-shell" data-lang="shell">kubectl get deployments</code></pre></figure>

<p>This command will display the list of deployments, and you should be able to see your application running.</p>

<h2 id="conclusion">Conclusion</h2>
<p>Migrating a legacy Python application to Kubernetes on Azure can be straightforward with the proper steps. This guide gives you the foundations to start this journey. The migration provides the benefits of containerization, and with Azure Kubernetes Service, you can easily manage, scale and deploy your applications. Enjoy the journey toward a cloud-native future.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Python" /><category term="Kubernetes" /><category term="Azure" /><summary type="html"><![CDATA[A step-by-step guide to migrating legacy Python applications to Kubernetes on Azure, from preparing your application and packaging it in a Docker container to deploying and testing it on Azure Kubernetes Service.]]></summary></entry><entry><title type="html">Event-Driven Scaling of Golang Applications in Azure Kubernetes Service (AKS) using KEDA</title><link href="https://www.faizanbashir.me/event-driven-scaling-of-golang-applications-in-azure-kubernetes-service-aks-using-keda" rel="alternate" type="text/html" title="Event-Driven Scaling of Golang Applications in Azure Kubernetes Service (AKS) using KEDA" /><published>2023-06-08T11:11:11+00:00</published><updated>2023-06-08T11:11:11+00:00</updated><id>https://www.faizanbashir.me/event-driven-scaling-of-golang-applications-in-azure-kubernetes-service-aks-using-keda</id><content type="html" xml:base="https://www.faizanbashir.me/event-driven-scaling-of-golang-applications-in-azure-kubernetes-service-aks-using-keda"><![CDATA[<h1 id="event-driven-scaling-of-golang-applications-in-azure-kubernetes-service-aks-using-keda">Event-Driven Scaling of Golang Applications in Azure Kubernetes Service (AKS) using KEDA</h1>

<p>This article will guide you through setting up event-driven scaling of a Golang application deployed in Azure Kubernetes Service (AKS) using Kubernetes Event-Driven Autoscaling (KEDA). KEDA is an open-source project that provides event-driven autoscaling for Kubernetes workloads.</p>

<h2 id="prerequisites">Prerequisites</h2>

<ul>
  <li>Go (version <code class="language-plaintext highlighter-rouge">1.16</code> or later): We’ll use Go to write our publisher and subscriber applications.</li>
  <li>Docker: We’ll use Docker to build and package our Go application.</li>
  <li>Kubernetes CLI (<code class="language-plaintext highlighter-rouge">kubectl</code>): We’ll use kubectl to interact with our Kubernetes cluster.</li>
  <li>Helm: We’ll use Helm to deploy KEDA on our Kubernetes cluster.</li>
</ul>

<p>Additionally, you’ll need an AKS cluster for deploying our application and KEDA. If you don’t have an AKS cluster ready to use, you can create an AKS cluster by following this <a href="https://docs.microsoft.com/en-us/azure/aks/intro-kubernetes">Azure documentation</a>.</p>

<hr />

<h1 id="table-of-contents">Table of Contents:</h1>

<ul>
  <li><a href="#deploying-keda-on-aks">Deploying KEDA on AKS</a></li>
  <li><a href="#building-a-golang-application-for-event-driven-scaling">Building a Golang Application for Event-Driven Scaling</a></li>
  <li><a href="#packaging-and-deploying-golang-application-in-aks">Packaging and Deploying Golang Application in AKS</a></li>
  <li><a href="#testing-event-driven-scaling">Testing Event-Driven Scaling</a></li>
  <li><a href="#conclusion">Conclusion</a></li>
</ul>

<hr />

<h2 id="deploying-keda-on-aks">Deploying KEDA on AKS</h2>

<p>We’ll use Helm, a Kubernetes package manager, to deploy KEDA on AKS. Run the following commands to add the KEDA Helm chart repository and install KEDA:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">helm repo add kedacore https://kedacore.github.io/charts
helm repo update
kubectl create namespace keda
helm <span class="nb">install </span>keda kedacore/keda <span class="nt">--namespace</span> keda</code></pre></figure>

<h2 id="building-a-golang-application-for-event-driven-scaling">Building a Golang Application for Event-Driven Scaling</h2>

<p>Let’s build a simple Golang application that reads messages from an Azure Storage Queue. The number of pods in the deployment will automatically scale up or go scale down based on the number of messages in the Azure Storage Queue. Here’s a simple Go script that reads messages from Azure Storage Queue:</p>

<figure class="highlight"><pre><code class="language-go" data-lang="go"><span class="k">package</span> <span class="n">main</span>

<span class="k">import</span> <span class="p">(</span>
    <span class="s">"context"</span>
    <span class="s">"fmt"</span>
    <span class="s">"github.com/Azure/azure-storage-queue-go/azqueue"</span>
    <span class="s">"os"</span>
<span class="p">)</span>

<span class="k">func</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">connectionString</span> <span class="o">:=</span> <span class="n">os</span><span class="o">.</span><span class="n">Getenv</span><span class="p">(</span><span class="s">"AZURE_STORAGE_CONNECTION_STRING"</span><span class="p">)</span>
    <span class="n">queueName</span> <span class="o">:=</span> <span class="n">os</span><span class="o">.</span><span class="n">Getenv</span><span class="p">(</span><span class="s">"QUEUE_NAME"</span><span class="p">)</span>
    <span class="n">queueURL</span> <span class="o">:=</span> <span class="n">azqueue</span><span class="o">.</span><span class="n">NewServiceURLFromConnectionString</span><span class="p">(</span><span class="n">connectionString</span><span class="p">)</span><span class="o">.</span><span class="n">NewQueueURL</span><span class="p">(</span><span class="n">queueName</span><span class="p">)</span>

    <span class="k">for</span> <span class="p">{</span>
        <span class="n">messagesURL</span> <span class="o">:=</span> <span class="n">queueURL</span><span class="o">.</span><span class="n">NewMessagesURL</span><span class="p">()</span>
        <span class="n">messages</span><span class="p">,</span> <span class="n">_</span> <span class="o">:=</span> <span class="n">messagesURL</span><span class="o">.</span><span class="n">Dequeue</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">Background</span><span class="p">(),</span> <span class="m">32</span><span class="p">,</span> <span class="m">30</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">message</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">messages</span><span class="o">.</span><span class="n">QueueMessages</span> <span class="p">{</span>
            <span class="n">fmt</span><span class="o">.</span><span class="n">Printf</span><span class="p">(</span><span class="s">"Processing message: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">*</span><span class="n">message</span><span class="o">.</span><span class="n">MessageText</span><span class="p">)</span>
            <span class="n">messageURL</span> <span class="o">:=</span> <span class="n">messagesURL</span><span class="o">.</span><span class="n">NewMessageIDURL</span><span class="p">(</span><span class="o">*</span><span class="n">message</span><span class="o">.</span><span class="n">MessageID</span><span class="p">)</span>
            <span class="n">messageURL</span><span class="o">.</span><span class="n">Delete</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">Background</span><span class="p">(),</span> <span class="n">message</span><span class="o">.</span><span class="n">PopReceipt</span><span class="p">)</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span></code></pre></figure>

<h2 id="packaging-and-deploying-golang-application-in-aks">Packaging and Deploying Golang Application in AKS</h2>

<p>We need to package our Go application using Docker. Create a <code class="language-plaintext highlighter-rouge">Dockerfile</code> for the same:</p>

<figure class="highlight"><pre><code class="language-dockerfile" data-lang="dockerfile"><span class="k">FROM</span><span class="s"> golang:1.16</span>

<span class="k">WORKDIR</span><span class="s"> /app</span>

<span class="k">COPY</span><span class="s"> go.mod ./</span>
<span class="k">COPY</span><span class="s"> go.sum ./</span>
<span class="k">RUN </span>go mod download

<span class="k">COPY</span><span class="s"> . .</span>

<span class="k">RUN </span>go build <span class="nt">-o</span> main .

<span class="k">CMD</span><span class="s"> [ "./main" ]</span></code></pre></figure>

<p>After building the Docker image and pushing it to a Docker registry, we create a Kubernetes deployment for our application. However, to enable KEDA, we need to create a <code class="language-plaintext highlighter-rouge">ScaledObject</code> which defines the scaling parameters:</p>

<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="na">apiVersion</span><span class="pi">:</span> <span class="s">keda.sh/v1alpha1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">ScaledObject</span>
<span class="na">metadata</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">golang-scaledobject</span>
<span class="na">spec</span><span class="pi">:</span>
  <span class="na">scaleTargetRef</span><span class="pi">:</span>
    <span class="na">name</span><span class="pi">:</span> <span class="s">golang-deployment</span>
  <span class="na">triggers</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="na">type</span><span class="pi">:</span> <span class="s">azure-queue</span>
    <span class="na">metadata</span><span class="pi">:</span>
      <span class="na">connectionFromEnv</span><span class="pi">:</span> <span class="s">AZURE_STORAGE_CONNECTION_STRING</span>
      <span class="na">queueName</span><span class="pi">:</span> <span class="s">myqueue</span>
      <span class="na">queueLength</span><span class="pi">:</span> <span class="s1">'</span><span class="s">5'</span></code></pre></figure>

<h2 id="testing-event-driven-scaling">Testing Event-Driven Scaling</h2>

<p>To test the event-driven scaling, add messages to the Azure Storage Queue and observe the number of pods of your Golang application. You should see more pods when there are more messages in the queue and fewer pods when there are fewer messages in the queue.</p>

<h2 id="conclusion">Conclusion</h2>

<p>This article walked you through setting up event-driven scaling of a Golang application in Azure Kubernetes Service using Kubernetes-based Event-Driven Autoscaling (KEDA). This capability is crucial in building highly scalable and responsive applications that automatically adjust their resources based on demand.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Golang" /><category term="Kubernetes" /><summary type="html"><![CDATA[Learn how to set up event-driven scaling of Golang applications in Azure Kubernetes Service using KEDA, an open-source project providing event-driven autoscaling for Kubernetes workloads.]]></summary></entry><entry><title type="html">Building a Messaging System with NATS, Golang, and Azure Kubernetes Service</title><link href="https://www.faizanbashir.me/building-a-messaging-system-with-nats-golang-and-azure-kubernetes-service" rel="alternate" type="text/html" title="Building a Messaging System with NATS, Golang, and Azure Kubernetes Service" /><published>2023-06-07T11:11:11+00:00</published><updated>2023-06-07T11:11:11+00:00</updated><id>https://www.faizanbashir.me/building-a-messaging-system-with-nats-golang-and-azure-kubernetes-service</id><content type="html" xml:base="https://www.faizanbashir.me/building-a-messaging-system-with-nats-golang-and-azure-kubernetes-service"><![CDATA[<h1 id="building-a-messaging-system-with-nats-golang-and-azure-kubernetes-service">Building a Messaging System with NATS, Golang, and Azure Kubernetes Service</h1>

<p>This article walks you through building a messaging system with NATS (an acronym for Neural Autonomic Transport System) and Golang deployed in Azure Kubernetes Service (AKS). NATS is an open-source messaging system. Written in the Go programming language. NATS has a core publish-subscribe server designed for performance, scalability, and ease of use.</p>

<h1 id="prerequisites">Prerequisites</h1>

<ul>
  <li>Go (version <code class="language-plaintext highlighter-rouge">1.16</code> or later): We’ll use Go to write our publisher and subscriber applications.</li>
  <li>Docker: We’ll use Docker to build and package our Go applications.</li>
  <li>Kubernetes CLI (<code class="language-plaintext highlighter-rouge">kubectl</code>): We’ll use kubectl to interact with our Kubernetes cluster.</li>
  <li>Helm: We’ll use Helm to deploy NATS on our Kubernetes cluster.</li>
</ul>

<p>You’ll also need access to an Azure Kubernetes Service (AKS) cluster. If you haven’t already, follow the Azure documentation to <a href="https://docs.microsoft.com/en-us/azure/aks/intro-kubernetes">create an AKS cluster</a>.</p>

<hr />

<h1 id="table-of-contents">Table of Contents:</h1>

<ul>
  <li><a href="#deploying-nats-on-azure-kubernetes-service">Deploying NATS on Azure Kubernetes Service</a></li>
  <li><a href="#creating-a-go-publisher-and-subscriber">Creating a Go Publisher and Subscriber</a></li>
  <li><a href="#running-the-go-applications-in-kubernetes">Running the Go Applications in Kubernetes</a></li>
  <li><a href="#deploying-to-kubernetes-and-testing">Deploying to Kubernetes and Testing</a></li>
  <li><a href="#conclusion">Conclusion</a></li>
</ul>

<hr />

<h2 id="deploying-nats-on-azure-kubernetes-service">Deploying NATS on Azure Kubernetes Service</h2>

<p>First, we’ll deploy a NATS server on our AKS cluster. We can do this easily using Helm, a package manager for Kubernetes. With Helm installed and your, AKS cluster up and running, execute the following commands to add the NATS Helm chart repo and install NATS:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">helm repo add nats https://nats-io.github.io/k8s/helm/charts/
helm repo update
helm <span class="nb">install </span>my-nats nats/nats</code></pre></figure>

<p>Helm will deploy a NATS server on your AKS cluster.</p>

<h2 id="creating-a-go-publisher-and-subscriber">Creating a Go Publisher and Subscriber</h2>

<p>Next, we’ll create a publisher and a subscriber application using Go. The publisher will publish messages to a NATS subject, and the subscriber will subscribe to this subject to receive these messages. Here’s a simple example of a publisher in the <code class="language-plaintext highlighter-rouge">publisher.go</code> file:</p>

<figure class="highlight"><pre><code class="language-go" data-lang="go"><span class="k">package</span> <span class="n">main</span>

<span class="k">import</span> <span class="p">(</span>
  <span class="s">"log"</span>
  <span class="s">"github.com/nats-io/nats.go"</span>
<span class="p">)</span>

<span class="k">func</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
  <span class="n">nc</span><span class="p">,</span> <span class="n">_</span> <span class="o">:=</span> <span class="n">nats</span><span class="o">.</span><span class="n">Connect</span><span class="p">(</span><span class="n">nats</span><span class="o">.</span><span class="n">DefaultURL</span><span class="p">)</span>
  <span class="n">log</span><span class="o">.</span><span class="n">Println</span><span class="p">(</span><span class="s">"Connected to "</span> <span class="o">+</span> <span class="n">nats</span><span class="o">.</span><span class="n">DefaultURL</span><span class="p">)</span>
  <span class="n">nc</span><span class="o">.</span><span class="n">Publish</span><span class="p">(</span><span class="s">"foo"</span><span class="p">,</span> <span class="p">[]</span><span class="kt">byte</span><span class="p">(</span><span class="s">"Hello World"</span><span class="p">))</span>
  <span class="n">log</span><span class="o">.</span><span class="n">Println</span><span class="p">(</span><span class="s">"Published message on subject 'foo'"</span><span class="p">)</span>
  <span class="n">nc</span><span class="o">.</span><span class="n">Close</span><span class="p">()</span>
<span class="p">}</span></code></pre></figure>

<p>And a subscriber in the <code class="language-plaintext highlighter-rouge">subscriber.go</code> file:</p>

<figure class="highlight"><pre><code class="language-go" data-lang="go"><span class="k">package</span> <span class="n">main</span>

<span class="k">import</span> <span class="p">(</span>
  <span class="s">"log"</span>
  <span class="s">"github.com/nats-io/nats.go"</span>
<span class="p">)</span>

<span class="k">func</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
  <span class="n">nc</span><span class="p">,</span> <span class="n">_</span> <span class="o">:=</span> <span class="n">nats</span><span class="o">.</span><span class="n">Connect</span><span class="p">(</span><span class="n">nats</span><span class="o">.</span><span class="n">DefaultURL</span><span class="p">)</span>
  <span class="n">log</span><span class="o">.</span><span class="n">Println</span><span class="p">(</span><span class="s">"Connected to "</span> <span class="o">+</span> <span class="n">nats</span><span class="o">.</span><span class="n">DefaultURL</span><span class="p">)</span>
  <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">Subscribe</span><span class="p">(</span><span class="s">"foo"</span><span class="p">,</span> <span class="k">func</span><span class="p">(</span><span class="n">m</span> <span class="o">*</span><span class="n">nats</span><span class="o">.</span><span class="n">Msg</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">log</span><span class="o">.</span><span class="n">Printf</span><span class="p">(</span><span class="s">"Received a message on %s: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">m</span><span class="o">.</span><span class="n">Subject</span><span class="p">,</span> <span class="kt">string</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">Data</span><span class="p">))</span>
  <span class="p">})</span>

  <span class="k">select</span> <span class="p">{}</span>
<span class="p">}</span></code></pre></figure>

<h2 id="running-the-go-applications-in-kubernetes">Running the Go Applications in Kubernetes</h2>

<p>Now we will containerize our Go applications using Docker. Here’s a basic <code class="language-plaintext highlighter-rouge">Dockerfile</code> for our Go applications:</p>

<figure class="highlight"><pre><code class="language-dockerfile" data-lang="dockerfile"><span class="k">FROM</span><span class="s"> golang:1.16</span>

<span class="k">WORKDIR</span><span class="s"> /app</span>

<span class="k">COPY</span><span class="s"> go.mod ./</span>
<span class="k">COPY</span><span class="s"> go.sum ./</span>
<span class="k">RUN </span>go mod download

<span class="k">COPY</span><span class="s"> *.go ./</span>

<span class="k">RUN </span>go build <span class="nt">-o</span> main .

<span class="k">CMD</span><span class="s"> ["/app/main"]</span></code></pre></figure>

<p>Build Docker images for both applications, tag them, and push them to a Docker registry. Here’s how you might do it:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">docker build <span class="nt">-t</span> publisher <span class="nb">.</span>
docker tag publisher:latest myregistry/publisher:latest
docker push myregistry/publisher:latest</code></pre></figure>

<p>Remember to replace <code class="language-plaintext highlighter-rouge">myregistry</code> with the name of your Docker registry.</p>

<h2 id="deploying-to-kubernetes-and-testing">Deploying to Kubernetes and Testing</h2>

<p>With our Docker images pushed to the registry, we can now deploy our applications to Kubernetes. We’ll create a deployment for each application, creating a pod for each.</p>

<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="na">apiVersion</span><span class="pi">:</span> <span class="s">apps/v1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Deployment</span>
<span class="na">metadata</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">publisher</span>
<span class="na">spec</span><span class="pi">:</span>
  <span class="na">replicas</span><span class="pi">:</span> <span class="m">1</span>
  <span class="na">selector</span><span class="pi">:</span>
    <span class="na">matchLabels</span><span class="pi">:</span>
      <span class="na">app</span><span class="pi">:</span> <span class="s">publisher</span>
  <span class="na">template</span><span class="pi">:</span>
    <span class="na">metadata</span><span class="pi">:</span>
      <span class="na">labels</span><span class="pi">:</span>
        <span class="na">app</span><span class="pi">:</span> <span class="s">publisher</span>
    <span class="na">spec</span><span class="pi">:</span>
      <span class="na">containers</span><span class="pi">:</span>
        <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">publisher</span>
          <span class="na">image</span><span class="pi">:</span> <span class="s">myregistry/publisher:latest</span>
<span class="nn">---</span>
<span class="na">apiVersion</span><span class="pi">:</span> <span class="s">apps/v1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Deployment</span>
<span class="na">metadata</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">subscriber</span>
<span class="na">spec</span><span class="pi">:</span>
  <span class="na">replicas</span><span class="pi">:</span> <span class="m">1</span>
  <span class="na">selector</span><span class="pi">:</span>
    <span class="na">matchLabels</span><span class="pi">:</span>
      <span class="na">app</span><span class="pi">:</span> <span class="s">subscriber</span>
  <span class="na">template</span><span class="pi">:</span>
    <span class="na">metadata</span><span class="pi">:</span>
      <span class="na">labels</span><span class="pi">:</span>
        <span class="na">app</span><span class="pi">:</span> <span class="s">subscriber</span>
    <span class="na">spec</span><span class="pi">:</span>
      <span class="na">containers</span><span class="pi">:</span>
        <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">subscriber</span>
          <span class="na">image</span><span class="pi">:</span> <span class="s">myregistry/subscriber:latest</span></code></pre></figure>

<p>Finally, we can test our setup by publishing a message. We should see this message appear in the logs of our subscriber:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">kubectl logs <span class="nt">-l</span> <span class="nv">app</span><span class="o">=</span>subscriber</code></pre></figure>

<h2 id="conclusion">Conclusion</h2>

<p>In this guide, we built a messaging system using NATS, Golang, and Azure Kubernetes Service. We deployed a NATS server onto AKS, made Golang publisher and subscriber applications, packaged them as Docker containers, and ran them on AKS. This guide is a basic introduction to NATS, Golang, and AKS. Feel free to expand upon this guide to build more complex systems tailored to your needs.</p>]]></content><author><name>Faizan Bashir</name></author><category term="Golang" /><category term="Kubernetes" /><summary type="html"><![CDATA[Learn how to build a messaging system using NATS, Golang, and Azure Kubernetes Service in our step-by-step guide.]]></summary></entry></feed>