<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohammed Vaghjipurwala on Medium]]></title>
        <description><![CDATA[Stories by Mohammed Vaghjipurwala on Medium]]></description>
        <link>https://medium.com/@mohammedvaghjipurwala?source=rss-d359846ff688------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UAICtfgNlW9ykYDREABhCg.jpeg</url>
            <title>Stories by Mohammed Vaghjipurwala on Medium</title>
            <link>https://medium.com/@mohammedvaghjipurwala?source=rss-d359846ff688------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:33:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohammedvaghjipurwala/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ From Complexity to Simplicity: How Serverless Architecture is Reshaping Development ]]></title>
            <link>https://levelup.gitconnected.com/from-complexity-to-simplicity-how-serverless-architecture-is-reshaping-development-055f3c9d9c18?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/055f3c9d9c18</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[solution-architecture]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Mon, 07 Apr 2025 14:32:28 GMT</pubDate>
            <atom:updated>2025-04-07T14:32:28.783Z</atom:updated>
            <content:encoded><![CDATA[<h4>Blog #5: Mastering Modern Systems: The Power of Solution Architecture Methodologies</h4><h4>Why is managing infrastructure outdated, and how serverless is redefining modern development</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*wY29M7zxI24oHwObNSsYjw.png" /></figure><blockquote><em>“Serverless computing is like electricity — you don’t generate it yourself, you just plug in and use what you need.”</em> — <strong>Werner Vogels, CTO of Amazon</strong></blockquote><p>In today’s fast-moving tech landscape, <strong>speed, scalability, and cost-efficiency</strong> are at the heart of modern software development. <strong>Serverless Architecture</strong> is emerging as a game-changer, enabling businesses to focus purely on building applications rather than managing infrastructure.</p><p>This blog is part of our <strong>“Mastering Modern Systems: The Power of Solution Architecture Methodologies”</strong> series — and also the final one. If you’ve followed the series so far, thank you for staying with us! If not, catch up with the earlier parts here:</p><ul><li><a href="https://medium.com/gitconnected/unlocking-the-power-of-solution-architecture-a-guide-to-methodologies-for-modern-systems-5b77de372a45">🧱 <strong>Unlocking the Power of Solution Architecture: A Guide to Methodologies for Modern Systems</strong> — Blog 1</a></li><li><a href="https://medium.com/gitconnected/%EF%B8%8F-understanding-monolithic-architecture-the-foundation-of-software-systems-d353e17d949b">🏛 <strong>Understanding Monolithic Architecture: The Foundation of Software Systems</strong> — Blog 2</a></li><li><a href="https://medium.com/gitconnected/breaking-the-monolith-crafting-scalable-systems-with-microservices-e5a67fbd9237">🔨 <strong>Breaking the Monolith: Crafting Scalable Systems with Microservices</strong> — Blog 3</a></li><li><a href="https://medium.com/gitconnected/architecting-for-scale-key-event-driven-patterns-you-need-to-know-71599fb4e62c"><strong>Architecting for Scale: Key Event-Driven Patterns You Need to Know </strong>— Blog 4</a></li></ul><p>In this concluding piece, we explore how <strong>serverless architecture</strong> simplifies software development, what makes it unique, and how you can start using it in your organization — whether you’re running monoliths, microservices, or something in between.</p><h3>🏗️ What is Serverless Architecture?</h3><p>Despite its name, “Serverless” doesn’t mean there are <strong>no servers</strong>. Instead, the <strong>management of servers is handled by cloud providers</strong>, allowing developers to focus solely on <strong>writing and deploying code</strong>.</p><p>In traditional architectures, developers must:<br> ✅ <strong>Provision servers</strong> (virtual machines, containers, or physical machines)<br> ✅ <strong>Manage scaling and load balancing</strong><br> ✅ <strong>Handle security patches and infrastructure monitoring</strong></p><p>With <strong>Serverless Architecture</strong>, these responsibilities shift to cloud providers like <strong>AWS Lambda, Azure Functions, and Google Cloud Functions</strong>. Applications are broken into <strong>small, event-driven functions</strong> that execute <strong>only when needed</strong> — this means <strong>zero idle costs and automatic scaling</strong>.</p><p>🔹 <strong>Example:</strong> Imagine an <strong>image processing application</strong> that scales up <strong>only when users upload images</strong> instead of running 24/7.</p><h4><strong><em>🔥 Key Features of Serverless:</em></strong></h4><ul><li><strong>Event-driven execution</strong> → Runs only when triggered.</li><li><strong>Fully managed infrastructure</strong> → No need for manual provisioning.</li><li><strong>Auto-scaling</strong> → Dynamically adjusts based on load.</li><li><strong>Cost-efficient</strong> → Pay <strong>only for execution time</strong>, no charges for idle servers.</li></ul><h3>🔄 How Does Serverless Architecture Work?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*OVKQ31tWT1neAO76tOoO_Q.png" /></figure><p>1️⃣ <strong>User Request/Trigger</strong> → A user action (like submitting a form or uploading a file) triggers an event.<br> 2️⃣ <strong>Cloud Provider Allocates Resources</strong> → The cloud platform provisions the required resources dynamically.<br> 3️⃣ <strong>Function Execution</strong> → The required function is executed, processes data, and returns a response.<br> 4️⃣ <strong>Resources Are Released</strong> → Once execution is complete, the allocated resources are freed, ensuring cost optimization.</p><h4>📌 Example: Serverless in Action</h4><ul><li>A <strong>video streaming service</strong> automatically <strong>resizes and optimizes videos</strong> using AWS Lambda when a user uploads them.</li><li>A <strong>customer support chatbot</strong> hosted on Google Cloud Functions automatically <strong>responds to queries</strong> without needing a running server.</li></ul><h3>🏗️ Core Serverless Design Patterns</h3><h4>🔄 Event-Driven Processing</h4><ul><li>Functions execute <strong>only when triggered by an event</strong> (database update, user request, file upload).</li><li><strong>Example:</strong> Real-time <strong>fraud detection</strong> in banking transactions.</li></ul><h4>🌉 API Gateway + FaaS (Function-as-a-Service)</h4><ul><li>API Gateway routes requests to backend functions instead of dedicated servers.</li><li><strong>Example:</strong> An <strong>e-commerce website</strong> dynamically generating product recommendations via serverless functions.</li></ul><h4>📊 Data Stream Processing</h4><ul><li>Serverless functions consume and process real-time data streams.</li><li><strong>Example:</strong> <strong>Uber</strong> using AWS Lambda and Kinesis for <strong>real-time ride location tracking</strong>.</li></ul><h4>🏗 Chaining Functions (Serverless Workflows)</h4><ul><li>Multiple functions are chained together to form a <strong>workflow</strong> (AWS Step Functions, Azure Durable Functions).</li><li><strong>Example:</strong> A <strong>travel booking system</strong> where one function verifies payment, another books flights, and another sends confirmation emails.</li></ul><h3>✅ Pros &amp; Cons of Serverless Architecture</h3><h4>✅ Advantages:</h4><ul><li>🚀 <strong>Rapid Deployment:</strong> Focus on writing code, not managing infrastructure.</li><li>💰 <strong>Cost-Efficiency:</strong> Pay <strong>only for execution time</strong>, no server maintenance.</li><li>🔧 <strong>Auto-Scaling:</strong> Functions scale <strong>instantly based on demand</strong>.</li><li>🛡 <strong>Built-in Security:</strong> Cloud providers handle <strong>patches, monitoring, and security</strong>.</li></ul><h4>❌ Challenges:</h4><ul><li>🛠 <strong>Cold Start Latency:</strong> Functions take time to initialize when idle.</li><li>🔄 <strong>Limited Execution Time:</strong> Serverless functions have a max execution duration (e.g., AWS Lambda: 15 min).</li><li>📊 <strong>Debugging Complexity:</strong> Logs are <strong>distributed across cloud services</strong>, making debugging harder.</li><li>🔍 <strong>State Management:</strong> Since functions are <strong>stateless</strong>, maintaining persistent state requires external storage (e.g., DynamoDB, Redis).</li></ul><h3>🔄 Transitioning to Serverless from Monolith/Microservices</h3><h4>🏗 From Monolith to Serverless</h4><p>1️⃣ Identify <strong>independent components</strong> (authentication, payments, notifications).<br> 2️⃣ Break them into <strong>serverless functions</strong>.<br> 3️⃣ Use <strong>API Gateway &amp; event-driven workflows</strong> to manage communication.</p><p><strong>Example: </strong>A <strong>legacy banking system</strong> moves <strong>customer notifications</strong> to AWS Lambda for real-time SMS/email alerts.</p><h4>🔄 From Microservices to Serverless</h4><p>1️⃣ Move <strong>compute-intensive microservices</strong> to serverless functions.<br> 2️⃣ Optimize database access to avoid <strong>latency issues</strong>.<br> 3️⃣ Implement <strong>event-driven orchestration</strong> using AWS Step Functions.</p><p><strong>Example: </strong>A <strong>stock trading platform</strong> replaces its <strong>trade processing service</strong> with AWS Lambda to reduce infrastructure costs.</p><h3>🌍 Real-World Example: Where Serverless Shines</h3><h4>🚀 Serverless in E-commerce</h4><p><em>📌 </em><strong><em>Scenario:</em></strong> A startup runs an e-commerce platform that <strong>struggles to handle peak sales events like Black Friday</strong>.<br> <em>📌 </em><strong><em>Problem:</em> </strong>High traffic crashes the monolithic system. Maintaining servers <strong>year-round</strong> for a one-day event is expensive.<br> <em>📌 </em><strong><em>Solution:</em> </strong>API Gateway + AWS Lambda for handling requests. DynamoDB for <strong>scalable product catalogs</strong>.<br> <em>📌 </em><strong><em>Results:</em> Zero downtime</strong>, 50% cost reduction, and <strong>seamless scaling</strong> during peak events.</p><h4>🏥 Serverless in Healthcare</h4><p><em>📌 </em><strong><em>Scenario:</em></strong> A hospital needs a <strong>real-time COVID-19 symptom tracker</strong> for patients.<br> <em>📌 </em><strong><em>Solution: </em></strong>AWS Lambda processes health data from <strong>wearable devices</strong>. S3 + QuickSight for <strong>real-time analytics dashboards</strong>.<br> <em>📌 </em><strong><em>Results: </em></strong>Doctors get <strong>instant alerts for critical patients</strong>, leading to <strong>faster intervention</strong>.</p><h3>🏁 Summing It Up</h3><p>Serverless <strong>removes infrastructure complexity</strong>, allowing developers to focus on <strong>building great products</strong>. It is ideal for <strong>event-driven applications</strong>, but <strong>choosing the right use case is key</strong>.</p><h3>💬 Share Your Thoughts!</h3><p>We’d love to hear from you! How has microservices architecture shaped your projects? Your experience, your challenges with microservices. Feel free to share your thoughts, or any questions in the comments 💬 below. Your feedback helps us create better content, so don’t hesitate to drop a clap 👏 and share this post if you found it useful. Constructive feedback is always welcome.</p><p>Thank you for reading, and see you in the next blog! 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=055f3c9d9c18" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/from-complexity-to-simplicity-how-serverless-architecture-is-reshaping-development-055f3c9d9c18">🔥 From Complexity to Simplicity: How Serverless Architecture is Reshaping Development 🚀</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Breaking the Monolith: Crafting Scalable Systems with Microservices ]]></title>
            <link>https://levelup.gitconnected.com/breaking-the-monolith-crafting-scalable-systems-with-microservices-e5a67fbd9237?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5a67fbd9237</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[microservicesarchitecture]]></category>
            <category><![CDATA[scalability]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Mon, 03 Mar 2025 15:30:17 GMT</pubDate>
            <atom:updated>2025-03-03T15:30:17.801Z</atom:updated>
            <content:encoded><![CDATA[<h4>Blog #3: Mastering Modern Systems: The Power of Solution Architecture Methodologies</h4><h4>Discover how Microservices Architecture transforms modern applications and paves the way for the future of software systems.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/0*geIyrZKcBVgTr4lZ.png" /></figure><blockquote>“In software design, the strength of a system lies in its ability to evolve — microservices make this evolution seamless.” — <em>Anonymous</em></blockquote><p>In the rapidly evolving tech landscape, <strong>Microservices Architecture</strong> has become a cornerstone for building large-scale, agile applications. It breaks away from the traditional monolithic structure by dividing applications into smaller, autonomous services, each focusing on a specific business capability. These services communicate with one another through well-defined APIs, ensuring modularity and scalability.</p><p>This blog is part of our <strong>“Mastering Modern Systems: The Power of Solution Architecture Methodologies”</strong> series. If you missed the previous blogs:</p><ol><li><a href="https://medium.com/gitconnected/unlocking-the-power-of-solution-architecture-a-guide-to-methodologies-for-modern-systems-5b77de372a45"><strong>Unlocking the Power of Solution Architecture: A Guide to Methodologies for Modern Systems</strong></a> — Blog 1</li><li><a href="https://medium.com/gitconnected/%EF%B8%8F-understanding-monolithic-architecture-the-foundation-of-software-systems-d353e17d949b"><strong>Understanding Monolithic Architecture: The Foundation of Software Systems</strong></a> — Blog 2</li></ol><p>Let’s dive into the details of <strong>Microservices Architecture</strong> — its principles, patterns, real-world applications, and how it stands out as the future of software design.</p><h3>🎩 What is Microservices Architecture?</h3><p><strong>Microservices Architecture</strong> is a software design paradigm that structures an application as a collection of loosely coupled services. Each service is independently deployable, highly maintainable, and responsible for a specific piece of business functionality. This independence enables teams to update or scale individual services without affecting the entire system, facilitating faster innovation and minimizing downtime during updates. These services communicate through lightweight protocols such as REST or messaging queues.</p><p><strong>In Layman’s Terms:</strong> Imagine a business composed of different departments (HR, Sales, IT). Each department works independently but collaborates for the company’s success. Microservices emulate this organizational model in software systems.</p><h3>Key Characteristics of Microservices Architecture</h3><ol><li><strong>Modularity:</strong> Applications are broken down into small, self-contained services that focus on specific business capabilities.</li><li><strong>Autonomy:</strong> Each service operates independently, with its own database and logic, reducing dependency on other services.</li><li><strong>Technology Agnostic:</strong> Teams can choose different technologies or programming languages for each service.</li><li><strong>Scalability:</strong> Each service can be scaled individually to handle high loads or spikes in demand.</li><li><strong>Fault Isolation:</strong> Failures in one service don’t cascade across the system, enhancing overall resilience.</li><li><strong>Continuous Delivery:</strong> Independent deployability allows faster releases and innovation.</li><li><strong>Decentralized Governance:</strong> Teams have ownership over their services, encouraging innovation and accountability.</li></ol><h3>🔄 Core Concepts of Microservices Architecture</h3><p>Here are the foundational principles that define microservices:</p><ol><li><strong>Single Responsibility Principle:<br></strong>Each service focuses on a single functionality, such as authentication, inventory, or payments.</li><li><strong>Decentralized Data Management:<br></strong>Each microservice can have its own database, ensuring independence.</li><li><strong>API-Driven Communication:<br></strong>Services communicate using lightweight APIs, such as REST, gRPC, or GraphQL.</li><li><strong>Autonomous Deployability:<br></strong>Services can be developed, tested, and deployed independently without impacting other components.</li></ol><p><strong>Example:</strong> Consider an e-commerce application divided into the following microservices:</p><ul><li><strong>Authentication Service:</strong> Manages user logins and security.</li><li><strong>Product Service:</strong> Handles product listings and inventory.</li><li><strong>Order Service:</strong> Processes and tracks customer orders.</li><li><strong>Payment Service:</strong> Manages payment processing.</li></ul><p>Each service can be scaled and updated independently without impacting the entire application. For instance, during high-traffic shopping seasons, the Checkout Service in an e-commerce platform can be scaled up without affecting the Product Browsing Service, ensuring both resilience and optimal performance.</p><h3>💡 How Does Microservices Architecture Work?</h3><p>Here’s a step-by-step example of how microservices operate in an e-commerce platform:</p><ol><li><strong>User Request:</strong> A customer searches for a product and places an order.</li><li><strong>API Gateway:</strong> Routes the user’s request to appropriate microservices (e.g., Product, Order, Payment).</li><li><strong>Inter-Service Communication:</strong> Services collaborate using APIs or messaging systems to process the request.</li><li><strong>Database Updates:</strong> Each service updates its respective database (e.g., inventory, orders, payments).</li><li><strong>Response:</strong> The user receives confirmation of their order.</li></ol><p><strong>Example Tools:</strong></p><ul><li><strong>API Gateway:</strong> Kong, AWS API Gateway, NGINX.</li><li><strong>Messaging Systems:</strong> Apache Kafka, RabbitMQ.</li></ul><h3>🏋️‍♂️ Core Microservices Design Patterns</h3><p>Let’s explore key design patterns in Microservices Architecture:</p><h3>1. Service Registry and Discovery 🔎</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*Xum7Aj-BGf6eE83RgPh9Uw.png" /></figure><p><strong>Definition:</strong> Enables dynamic discovery of services within the ecosystem, ensuring seamless communication.</p><p><strong>Example:</strong> A Payment Service needs to locate the Order Service. Instead of hardcoding its address, it queries the service registry for the latest endpoint.</p><p><strong>Use Case:</strong> Systems with frequent service updates or scaling, like ride-hailing apps (Uber, Lyft).</p><p><strong>Tools:</strong> Consul, Eureka, Zookeeper.</p><h3>2. Circuit Breaker ⚡</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*qK-zFuqkrK9i5ywZOshn0g.png" /></figure><p><strong>Definition:</strong> Prevents cascading failures by halting requests to a failing service after a certain threshold.</p><p><strong>Example:</strong> If the Payment Service fails, the Circuit Breaker prevents further calls and returns a fallback response.</p><p><strong>Use Case:</strong> Critical systems requiring high availability, such as banking apps.</p><p><strong>Tools:</strong> Netflix Hystrix, Resilience4j.</p><h3>3. Event-Driven Architecture 🎵</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*g9aTWGRr3-XSUKpU8W26mw.png" /></figure><p><strong>Definition:</strong> Services communicate by publishing and subscribing to events.</p><p><strong>Example:</strong> In an e-commerce app, when an order is placed, the Order Service emits an “Order Placed” event, triggering the Inventory and Shipping Services.</p><p><strong>Use Case:</strong> Real-time updates, such as stock trading platforms or IoT systems.</p><p><strong>Tools:</strong> Apache Kafka, RabbitMQ.</p><h3>4. Sidecar Pattern 🏙️</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*itOgi-WDsrD0rIxPbkRjpg.png" /></figure><p><strong>Definition:</strong> Attaches auxiliary tasks (e.g., logging, monitoring) as a sidecar process to the primary service.</p><p><strong>Example:</strong> A Payment Service with a sidecar for logging and security.</p><p><strong>Use Case:</strong> Applications requiring enhanced observability and security.</p><p><strong>Tools:</strong> Envoy, Istio, Linkerd.</p><h3>5. API Gateway Pattern 🚪</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*ts_ZJm7YB9jDtY4sCOHYCQ.png" /></figure><p><strong>Definition:</strong> Acts as a single entry point for client requests, routing them to appropriate microservices.</p><p><strong>Example:</strong> An e-commerce platform uses an API Gateway to handle authentication, product browsing, and order placement through one endpoint.</p><p><strong>Use Case:</strong> Reducing complexity for client applications.</p><p><strong>Tools:</strong> AWS API Gateway, Kong, Apigee.</p><h3>6. Database Per Service 🗄️</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*XCL9Uy9z7veJUaHnLkOPMQ.png" /></figure><p><strong>Definition:</strong> Each microservice has its own dedicated database to ensure independence and avoid coupling.</p><p><strong>Example:</strong> The Order Service uses PostgreSQL, while the Product Service uses MongoDB.</p><p><strong>Use Case:</strong> Ensures scalability and technology flexibility.</p><p><strong>Tools:</strong> MySQL, PostgreSQL, MongoDB.</p><h3>7. Bulkhead Pattern 🚢</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*ouR1YgKiysAi1FZYag4lgg.png" /></figure><p><strong>Definition:</strong> Isolates critical resources to prevent a single service failure from impacting others.</p><p><strong>Example:</strong> Separate thread pools for Payment and Order Services to avoid overload.</p><p><strong>Use Case:</strong> High-resilience systems like airline booking platforms.</p><p><strong>Tools:</strong> Thread pools, Resilience4j.</p><h3>8. Saga Pattern 📖</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*ow1bDI7zh8lPuixaeCa8ng.png" /></figure><p><strong>Definition:</strong> Manages distributed transactions using a sequence of compensating actions.</p><p><strong>Example:</strong> If an order placement fails, the Saga rolls back inventory updates and payment transactions.</p><p><strong>Use Case:</strong> Applications requiring consistency across multiple services.</p><p><strong>Tools:</strong> Orchestration tools like Camunda, Zeebe.</p><h3>9. Strangler Fig Pattern 🌳</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*-959-tQr7ksH99YlhHehsQ.png" /></figure><p><strong>Definition:</strong> Incrementally replaces monolithic components with microservices.</p><p><strong>Example:</strong> An e-commerce platform gradually migrates its checkout module to a microservice.</p><p><strong>Use Case:</strong> Smooth transition from monolith to microservices.</p><p><strong>Tools:</strong> Kubernetes, Docker.</p><h3>10. CQRS (Command Query Responsibility Segregation) 📊</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*eEz_3g_qM_BwoBadDIy0wQ.png" /></figure><p><strong>Definition:</strong> Separates read and write operations into different models for scalability.</p><p><strong>Example:</strong> A Reporting Service uses a read-optimized database, while a Billing Service uses a write-optimized one.</p><p><strong>Use Case:</strong> High-traffic applications with distinct read/write workloads.</p><p><strong>Tools:</strong> Axon Framework, Eventuate.</p><h3>🌍 Real-World Use Cases for Microservices</h3><p>Microservices are used across both mainstream and niche industries to build scalable, flexible, and resilient systems. Here are six top real-world use cases:</p><p><strong>E-Commerce Platforms 🛒</strong></p><ul><li><strong>Use Case:</strong> In e-commerce, microservices enable independent scaling of services like user authentication, product management, and payments. This ensures high availability during peak traffic and rapid deployment of new features.</li><li><strong>Example:</strong> <strong>Amazon</strong> uses microservices to run independent services like catalog management, payment processing, and order fulfillment, ensuring that each service can be scaled according to demand.</li></ul><p><strong>Streaming Services 🎬</strong></p><ul><li><strong>Use Case:</strong> Streaming platforms require scalability and fast content delivery. Microservices help manage different functions such as content catalog, user profiles, and playback services.</li><li><strong>Example:</strong> <strong>Netflix</strong> uses microservices to manage its large-scale infrastructure for streaming, providing dynamic scaling and high availability to handle millions of simultaneous viewers.</li></ul><p><strong>Healthcare Systems 🏥</strong></p><ul><li><strong>Use Case:</strong> Hospitals and health organizations utilize microservices to manage patient records, appointments, lab results, and medical billing separately, ensuring flexibility and security. Microservices enable integration with other systems like insurance providers and pharmacy systems.</li><li><strong>Example:</strong> <strong>The NHS</strong> (National Health Service) in the UK uses microservices to provide a digital ecosystem where healthcare services, patient portals, and appointment booking systems operate independently.</li></ul><p><strong>Gaming Platforms 🎮</strong></p><ul><li><strong>Use Case:</strong> Multiplayer online games, where each game instance or user session requires independent handling, benefit from microservices. This architecture helps in managing user profiles, game sessions, leaderboards, and in-app purchases at scale.</li><li><strong>Example:</strong> <strong>Epic Games</strong> leverages microservices to enable smooth scaling of their Fortnite game infrastructure, allowing for a high number of concurrent players across various regions.</li></ul><p><strong>IoT Applications 🌐</strong></p><ul><li><strong>Use Case:</strong> In Internet of Things (IoT) applications, microservices help in managing sensor data, device management, and user notifications independently. Each device or sensor can be handled by a separate service, allowing for quick modifications and scaling.</li><li><strong>Example:</strong> <strong>GE Predix</strong> platform uses microservices to manage connected industrial devices and sensors, offering predictive maintenance and analytics for industries like aviation and manufacturing.</li></ul><p><strong>Telecom Networks 📱</strong></p><ul><li><strong>Use Case:</strong> Telecom operators use microservices to handle different parts of their networks like billing, user management, call routing, and real-time analytics. By isolating services, telecoms can scale independently and handle heavy user traffic more efficiently.</li><li><strong>Example:</strong> <strong>AT&amp;T</strong> uses microservices in their telecom architecture to improve service reliability and customer experience by dynamically scaling network resources.</li></ul><h3>🚀 Pros and Cons of Microservices Architecture</h3><h4>Pros:</h4><ol><li><strong>Scalability:<br></strong>Individual services can scale based on demand.<br><strong>Example:</strong> A food delivery app can scale its Order Service during peak hours.</li><li><strong>Technology Flexibility:<br></strong>Different services can use different tech stacks.<br><strong>Example:</strong> An Inventory Service might use Python, while the Payment Service uses Java.</li><li><strong>Faster Development:<br></strong>Independent teams can build and deploy services concurrently.</li><li><strong>Resilience and Fault Isolation 🔒<br></strong>If one service fails, it does not bring down the entire system. Microservices can handle failures gracefully, using patterns like Circuit Breaker to isolate issues and ensure overall system reliability.</li><li><strong>Easy Maintenance and Updates 🔧<br></strong>Since each service is smaller and focused on a specific function, maintaining and updating services is easier. A small change to a service doesn’t require a full redeployment of the entire application.</li><li><strong>Improved Developer Productivity 👨‍💻<br></strong>Developers can focus on specific services, improving their expertise in a particular area. It also allows for decentralized decision-making, increasing agility within development teams.</li></ol><h4>Cons:</h4><ol><li><strong>Complexity in Management 🧠<br></strong>Microservices introduce complexity in managing multiple services, APIs, and databases. Keeping track of all the moving parts can become challenging, especially as the system grows.</li><li><strong>Deployment Complexity 🔄<br></strong>Deploying microservices requires sophisticated DevOps tools and continuous integration/continuous deployment (CI/CD) pipelines to handle frequent deployments and service orchestration.</li><li><strong>Higher Resource Overhead ⚙️<br></strong>Microservices often require more resources, such as CPU, memory, and networking, compared to monolithic systems. This can lead to higher operational costs, particularly in smaller applications.</li><li><strong>Increased Network Latency 🌐<br></strong>Since services communicate over the network, the communication overhead can lead to increased latency. This is especially important for high-performance applications where low latency is crucial.</li><li><strong>Data Consistency Challenges ⚖️<br></strong>Managing data consistency across microservices can be challenging, especially when each service has its own database. Ensuring that data remains consistent across services requires advanced patterns like Saga or Eventual Consistency.</li></ol><h3>🔄 <strong>Transitioning from Monolith to Microservices</strong></h3><p>For many organizations, moving from a monolithic architecture to microservices is an essential step toward scalability, flexibility, and faster time to market. However, transitioning isn’t always straightforward. Here’s a roadmap to help you navigate the process:</p><ol><li><strong>Understand the Challenges:<br></strong>The transition to microservices can be complex due to issues like data consistency, inter-service communication, and the need for a new development and deployment strategy. A well-defined approach is necessary to manage these complexities.</li><li><strong>Start Small — Strangler Fig Pattern:<br></strong>Start by identifying the most critical parts of the application and convert them into microservices. The <strong>Strangler Fig Pattern</strong> allows you to replace legacy monolithic components gradually, reducing risk and minimizing downtime.</li><li><strong>Define Service Boundaries:<br></strong>Carefully define the boundaries of each service. A common mistake is having services that are either too broad (e.g., an “Order” service that handles everything) or too fine-grained (e.g., a service that only handles a single HTTP request). Aim for a service that focuses on a distinct business capability.</li><li><strong>Implement Effective Communication Mechanisms:<br></strong>Use <strong>API Gateways</strong> to manage and route traffic between services. <strong>Messaging systems</strong> like Kafka or RabbitMQ can help decouple services and allow for asynchronous communication.</li><li><strong>Focus on Data Decentralization:<br></strong>One of the core principles of microservices is decentralized data management. Each service should have its own database, reducing the risk of a single point of failure and ensuring scalability.</li><li><strong>Automate Testing and Deployment:<br></strong>Microservices require automated testing and continuous deployment pipelines to ensure each service can be independently developed, tested, and deployed without impacting other services.</li></ol><h3>📈 Summing It Up</h3><p>Microservices Architecture revolutionizes software design, offering unparalleled scalability and flexibility. While it introduces complexity, its advantages for large-scale, dynamic systems are undeniable.</p><blockquote><em>“The best architectures enable innovation by embracing change and decentralizing control.”</em> — Anonymous</blockquote><h3>👚 Next in the Series</h3><p>In our next blog, we’ll explore <strong>Serverless Architecture</strong> — its rise, benefits, and how it simplifies software development. The next post is tentatively scheduled for two weeks from now. Check the comments for the link once it’s live. Stay tuned!</p><h3>💬 Share Your Thoughts</h3><p>We’d love to hear from you! How has microservices architecture shaped your projects? Your experience, your challenges with microservices. Feel free to share your thoughts, or any questions in the comments 💬 below. Your feedback helps us create better content, so don’t hesitate to drop a clap 👏 and share this post if you found it useful. Constructive feedback is always welcome.</p><p>Thank you for reading, and see you in the next post! 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5a67fbd9237" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/breaking-the-monolith-crafting-scalable-systems-with-microservices-e5a67fbd9237">🔨 Breaking the Monolith: Crafting Scalable Systems with Microservices 🚀</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[️ Understanding Monolithic Architecture: The Foundation of Software Systems]]></title>
            <link>https://levelup.gitconnected.com/%EF%B8%8F-understanding-monolithic-architecture-the-foundation-of-software-systems-d353e17d949b?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/d353e17d949b</guid>
            <category><![CDATA[modern-architecture]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[monolithic-architecture]]></category>
            <category><![CDATA[tech-trends]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Fri, 20 Dec 2024 12:12:54 GMT</pubDate>
            <atom:updated>2024-12-20T12:12:54.754Z</atom:updated>
            <content:encoded><![CDATA[<h4>Blog #2: Mastering Modern Systems: The Power of Solution Architecture Methodologies</h4><h4>Discover how monolithic architectures work, their design patterns, real-world examples, and the journey to modern architectures</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*DLZX73XF5u7ihCi0e9IVGw.png" /></figure><p>In today’s evolving world of software development, <strong>Monolithic Architecture</strong> remains a foundational approach for building applications. It is where most software journeys begin, and understanding its design, strengths, and challenges is crucial for architects and developers alike. While newer architectures like <strong>Microservices</strong> and <strong>Serverless</strong> dominate the tech conversation, monoliths are the stepping stone for these modern systems.</p><p>This blog is part of our <strong>“Mastering Modern Systems: The Power of Solution Architecture Methodologies”</strong> series, where we explore software architectures, their design patterns, and how they are shaping the future</p><blockquote>“A monolith may seem like a giant rock, but sometimes it forms the foundation of the tallest structures.” — <em>Anonymous</em></blockquote><p>If you missed the first blog, <strong>“Unlocking the Power of Solution Architecture: A Guide to Methodologies for Modern Systems,”</strong> where we introduced core concepts and methodologies for modern architectures, check it out <a href="https://medium.com/gitconnected/architecting-for-scale-key-event-driven-patterns-you-need-to-know-71599fb4e62c">here</a>.</p><p>Now, let’s dive deep into <strong>Monolithic Architecture</strong> — its concepts, patterns, use cases, pros and cons, and how organizations transition from monoliths to modern systems like microservices.</p><h4>🔢 What is Monolithic Architecture?</h4><p>A <strong>Monolithic Architecture</strong> is a traditional software design model where all components of an application — the user interface, business logic, and database — are built as a single, unified unit.</p><p>In simple terms, it’s like <strong>a big, all-in-one machine</strong> where every part works together under one roof. Everything is interconnected, and any changes require modifying the whole system.</p><p><strong>Key Characteristics:</strong></p><ul><li>Single codebase for the entire application</li><li>Unified deployment (one package, one server)</li><li>Tightly coupled components</li></ul><h4>🧐 Core Concepts of Monolithic Architecture</h4><p>Monolithic systems are organized into <strong>layers</strong> that serve distinct roles:</p><ol><li><strong>Presentation Layer (UI):</strong><br>Handles user interaction. For example, a web page where users browse products or input data.</li><li><strong>Business Logic Layer:</strong><br>Contains the application’s core rules and processes, such as calculations, validations, and data processing.</li><li><strong>Data Access Layer:</strong><br>Manages communication between the business logic and the database.</li><li><strong>Database Layer:</strong><br>Stores application data in a centralized database.</li></ol><p><strong>Example:</strong> In a traditional e-commerce system:</p><ul><li>The <strong>Presentation Layer</strong> displays product listings and shopping carts.</li><li>The <strong>Business Logic Layer</strong> calculates prices, applies discounts, and processes orders.</li><li>The <strong>Data Access Layer</strong> retrieves inventory and user data from the database.</li><li>The <strong>Database Layer</strong> stores user orders, products, and stock levels.</li></ul><h4>🛠️ How Monolithic Architecture Works</h4><p>Here’s a step-by-step example of how a monolithic system works:</p><ol><li><strong>User Request:</strong> A user places an order on an e-commerce website.</li><li><strong>Processing:</strong> The request travels to the server.</li><li><strong>Business Logic:</strong> The application checks inventory, validates payment, and processes the order.</li><li><strong>Database Access:</strong> The system updates the product stock and order records.</li><li><strong>Response:</strong> The order confirmation is displayed to the user.</li></ol><p><em>Everything happens within a single application package.</em></p><p><strong>Example Tools:</strong></p><ul><li><strong>Frameworks:</strong> Spring Boot, Django, Ruby on Rails.</li><li><strong>Databases:</strong> PostgreSQL, MySQL.</li></ul><h4>🌾 Evolution of Monolithic Architecture</h4><p>In the early 2000s, software development relied on monoliths because:</p><ul><li><strong>Simpler Infrastructure:</strong> Applications ran on on-premise servers with limited scaling needs.</li><li><strong>Single Codebase:</strong> All functionality lived in one place, making development easier.</li><li><strong>Centralized Teams:</strong> Development teams managed the entire lifecycle of a single application.</li></ul><p><strong>Example:</strong> Early versions of Facebook and Twitter were monolithic applications due to their simpler infrastructure requirements.</p><p>However, as software systems became more complex and demand for scalability increased, monoliths began showing their limitations, such as slower deployments and difficulty scaling. This evolution led to the rise of <strong>microservices</strong> and modular designs.</p><h4>🕹️ Core Monolithic Design Patterns</h4><p>Let’s explore the most common monolithic design patterns:</p><ol><li><strong><em>Layered Architecture 🧱</em></strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*x7em_MNVoF3e-fMGpRNWsw.png" /></figure><p><strong>Definition:</strong> The application is divided into distinct layers — typically Presentation, Business Logic, and Data Access.</p><p><strong>Example:</strong> In a blogging platform:</p><ul><li>The <strong>Presentation Layer</strong> serves HTML pages.</li><li>The <strong>Business Logic Layer</strong> processes blog creation and edits.</li><li>The <strong>Data Access Layer</strong> retrieves posts from the database.</li></ul><p><strong>Use Case:</strong> Ideal for applications with clear separation of concerns.</p><p><strong>Tools:</strong> Spring Framework, Django, Laravel.</p><p><strong><em>2. MVC (Model-View-Controller) 🎛️</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*yJso99OWZuzwbw-synm85A.png" /></figure><p><strong>Definition:</strong> Separates the application into three parts:</p><ul><li><strong>Model:</strong> Represents data and business logic.</li><li><strong>View:</strong> Displays the user interface.</li><li><strong>Controller:</strong> Handles user input and connects the View to the Model.</li></ul><p><strong>Example:</strong> A to-do app where:</p><ul><li><strong>Model</strong> manages the task list.</li><li><strong>View</strong> displays the tasks.</li><li><strong>Controller</strong> updates tasks when users interact.</li></ul><p><strong>Use Case:</strong> Suitable for applications with complex UI requirements.</p><p><strong>Tools:</strong> ASP.NET MVC, Flask, Ruby on Rails.</p><p><strong><em>3. Monolithic Modularization 🛠️</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*HxB0l_bKtwyJWKDPVSCb5w.png" /></figure><p><strong>Definition:</strong> Break the codebase into smaller modules within the monolithic structure.</p><p><strong>Example:</strong> A healthcare app with modules for <strong>patient management</strong>, <strong>appointments</strong>, and <strong>billing</strong>.</p><p><strong>Use Case:</strong> Perfect for large systems that need better code organization without breaking the monolith.</p><p><strong>Tools:</strong> Java packages, Python modules.</p><h4>📊 Real-World Use Cases for Monolithic Architecture</h4><p>Monolithic architectures continue to be widely used in various industries and scenarios:</p><ol><li><strong>Startups and Small Projects 🚀</strong><br>Monolithic systems are a great choice for early-stage companies or startups that need to quickly develop and deploy a product. By having a single codebase, development teams can focus on building core features without worrying about complex system integration.<br><strong>Example:</strong> Early versions of Instagram and Airbnb were monolithic apps, enabling rapid development before scaling to more complex systems.</li><li><strong>Legacy Enterprise Systems 🏢</strong><br>Large enterprises, especially in sectors like banking, government, and insurance, often rely on monolithic systems. These applications were built years ago and still run on legacy monolithic architectures due to their stability, simplicity, and low-cost maintenance in a highly regulated environment.<br><strong>Example:</strong> Many government systems and legacy financial platforms still operate on monolithic architectures.</li><li><strong>Rapid MVP Development 🏗️</strong><br>Startups and small teams can quickly launch Minimum Viable Products (MVPs) using a monolithic architecture. This enables faster iteration and reduces overhead before scaling up to more complex architectures like microservices.<br><strong>Example:</strong> A healthcare startup might choose a monolithic architecture for its first version of an appointment scheduling platform to minimize development time and focus on core features.</li><li><strong>SaaS Platforms with Stable Requirements 🌐</strong><br>SaaS companies that offer standardized solutions with limited customizations often benefit from monolithic architectures. These platforms don’t require the flexibility of microservices and can efficiently handle their user load with a single unified system.<br><strong>Example:</strong> A project management tool like Trello, in its early stages, might adopt a monolithic design to keep development simple and focus on adding features quickly.</li><li><strong>Internal Tools for Small Teams 🛠️</strong><br>For smaller teams or internal tools with straightforward functionality, monolithic architectures provide simplicity. Applications such as internal CRM systems or employee management tools can run efficiently in a monolithic structure.<br><strong>Example:</strong> A small business managing its customer support ticketing system might choose a monolith to streamline development and deployment.</li></ol><h4>💡 Pros and Cons of Monolithic Architecture</h4><p><strong><em>✅ Pros:</em></strong></p><ul><li><strong>Simpler Development and Deployment</strong></li><li><strong>Faster Testing and Debugging</strong></li><li><strong>Performance Benefits</strong> (fewer network calls)</li><li><strong>Low Infrastructure Overhead</strong></li></ul><p>❌<strong><em> Cons:</em></strong></p><ul><li><strong>Hard to Scale</strong> individual components</li><li><strong>Slower Deployments</strong> as the app grows</li><li><strong>Complex Maintenance</strong> in large systems</li><li><strong>Technology Lock-In</strong> (hard to use new tech for specific parts)</li></ul><h4>🛡️ Transitioning from Monolith to Modern Architectures</h4><p>Transitioning from monoliths to microservices involves:</p><ol><li><strong>Identify Boundaries</strong>: Split functionality into logical modules.</li><li><strong>API Integration</strong>: Expose module functionalities via APIs.</li><li><strong>Refactor Incrementally</strong>: Migrate one module at a time.</li><li><strong>Use Containers</strong>: Tools like <strong>Docker</strong> and <strong>Kubernetes</strong> help with microservices.</li><li><strong>Monitor and Test</strong>: Use tools like Prometheus, Grafana, and Jaeger.</li></ol><h4>🔄 Summing It Up</h4><p>Monolithic architectures aren’t disappearing anytime soon. While microservices and serverless are gaining popularity, monoliths still offer value, especially for startups, small teams, or simpler applications. They provide quick development and deployment with lower infrastructure needs.</p><p>Looking ahead, we may see monolithic systems evolve, incorporating more modularity and scalability, possibly using microservices within a monolithic framework or containerization. The key is understanding when and how to use monoliths effectively, as they still have a place in the future of software design.</p><blockquote>“Good architecture doesn’t just solve current problems; it creates pathways for future growth.” — <em>Anonymous</em></blockquote><h4>🖐️ Next in the Series</h4><p>In our next blog, we’ll dive deep into <strong>Microservices Architecture</strong> — its benefits, challenges, and why it’s the future of scalable software design. The next post is tentatively scheduled for two weeks from now. Check the comments for the link once it’s live. Stay tuned!</p><h4>💬 Share Your Thoughts!</h4><p>We’d love to hear from you! How has monolithic architecture shaped your projects? Your experience, your challenges with monoliths. Feel free to share your thoughts, or any questions in the comments 💬 below. Your feedback helps us create better content, so don’t hesitate to drop a clap 👏 and share this post if you found it useful. Constructive feedback is always welcome.</p><p>Thank you for reading, and see you in the next post! 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d353e17d949b" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/%EF%B8%8F-understanding-monolithic-architecture-the-foundation-of-software-systems-d353e17d949b">🏗️ Understanding Monolithic Architecture: The Foundation of Software Systems</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Unlocking the Power of Solution Architecture: A Guide to Methodologies for Modern Systems]]></title>
            <link>https://levelup.gitconnected.com/unlocking-the-power-of-solution-architecture-a-guide-to-methodologies-for-modern-systems-5b77de372a45?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b77de372a45</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[tech-trends]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Mon, 02 Dec 2024 02:18:33 GMT</pubDate>
            <atom:updated>2024-12-02T02:18:33.733Z</atom:updated>
            <content:encoded><![CDATA[<h4>From Mainframes to Microservices: The Story of Modern Architecture</h4><p>In the ever-evolving tech world, where innovation drives success, the backbone of every successful digital solution is its <strong>architecture</strong>. Whether you’re building a sleek e-commerce platform, a resilient financial system, or a smart IoT network, <strong>Solution Architecture</strong> is the unsung hero that makes it all possible.</p><p>💡 <em>“The beautiful thing about learning is that nobody can take it away from you.”</em> — B.B. King</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6gkTSGWlZUynU3_bYpufNA.png" /></figure><p>Welcome to the first installment of our blog series, <strong>“Mastering Modern Systems: The Power of Solution Architecture Methodologies”</strong> In this post, we’ll explore what Solution Architecture is, why methodologies matter, and give you a sneak peek into five transformative approaches that shape how systems are designed today.</p><h3>📐 What is Solution Architecture?</h3><p>Imagine you’re building a house. You need a blueprint that considers the foundation, structure, plumbing, and aesthetics. Solution Architecture is the equivalent of this blueprint for software systems.</p><p><strong>Solution Architecture</strong> defines how different components — databases, applications, interfaces — interact to achieve a specific business objective. It ensures that the technical design aligns seamlessly with the organization’s goals.</p><h3>Key Responsibilities of a Solution Architect:</h3><ul><li><strong>Connecting Business and Technology</strong>: Act as the key link between business stakeholders and technical teams, ensuring <strong>business requirements</strong> are effectively translated into <strong>scalable, reliable technical solutions</strong> that align with long-term product goals.</li><li><strong>Defining System Architecture</strong>: Lead the design of the <strong>overall system architecture</strong>, ensuring it fits within the business vision and addresses <strong>technical challenges</strong> throughout the entire <strong>product development lifecycle</strong>.</li><li><strong>Choosing the Right Tools and Technologies</strong>: Select the best <strong>technologies</strong>, <strong>frameworks</strong>, and <strong>architecture patterns</strong> that support the product’s goals, ensuring solutions are <strong>efficient</strong>, <strong>scalable</strong>, and can evolve with future needs.</li><li><strong>Facilitating Seamless Integration</strong>: Ensure the system components work in harmony through <strong>efficient integration</strong>, enabling smooth communication between services, <strong>third-party systems</strong>, and other essential components.</li><li><strong>Ensuring Scalability and Performance</strong>: Design the system to support <strong>growing user bases</strong> and dynamic workloads, focusing on <strong>performance</strong>, <strong>scalability</strong>, and efficient use of resources, allowing the system to handle future demands.</li><li><strong>Securing and Complying with Regulations</strong>: Prioritize <strong>data security</strong>, manage <strong>user privacy</strong>, and ensure the system complies with industry standards and <strong>regulations</strong>, such as GDPR or HIPAA, throughout its lifecycle.</li><li><strong>Managing Risk and Reducing Technical Debt</strong>: Identify potential risks early in the development process and tackle <strong>technical debt</strong> proactively, minimizing issues that could affect the product in the future.</li><li><strong>Guiding Teams and Setting Standards</strong>: Provide <strong>leadership</strong> and technical direction to both <strong>development</strong> and <strong>DevOps teams</strong>, establishing best practices, reviewing code, and ensuring smooth collaboration across the team.</li><li><strong>Aligning with Strategic Business Goals</strong>: Ensure that the architecture and technology choices directly support <strong>company objectives</strong>, helping drive growth, enhance user experience, and maintain a competitive edge.</li><li><strong>Driving Continuous Improvement</strong>: Regularly review system performance, gather user feedback, and oversee <strong>iterative improvements</strong>, ensuring that the solution adapts to meet both current and future business needs.</li></ul><h3>🌍 <strong>Real-World Example:</strong></h3><p>Think of Netflix, a prime example of a modern solution architecture. The platform’s ability to stream content globally, recommend shows, and handle millions of concurrent users is no accident. Netflix’s solution architecture, based on <strong>Microservices</strong> and <strong>Event-Driven Design</strong>, is a key factor behind its success. It ensures flexibility, scalability, and an outstanding user experience for millions of users worldwide.</p><h3>🔮 Preview of the Series: A Sneak Peek into the Approaches</h3><p>Here’s a glimpse into the methodologies that followed and revolutionized solution architecture:</p><h4>1. Monolithic Architecture</h4><p>The classic approach where all functionalities reside in a single application. It’s simple to build but can become a bottleneck for growing businesses.</p><ul><li><strong>Example</strong>: Many early-stage startups adopt Monolithic Architecture for their MVPs.</li></ul><h4>2. Microservices Architecture</h4><p>A modern, modular approach where each service is an independent entity. This methodology powers systems like Amazon and Netflix.</p><ul><li><strong>Example</strong>: Amazon’s product recommendation engine operates independently of its inventory systems.</li></ul><h4>3. Event-Driven Architecture (EDA)</h4><p>Ideal for real-time applications, EDA uses events as triggers for system processes.</p><ul><li><strong>Example</strong>: Payment gateways use EDA to send real-time notifications about transaction status.</li></ul><h4>4. Serverless Architecture</h4><p>Focus on writing code, and let the cloud provider handle the infrastructure. Perfect for dynamic applications.</p><ul><li><strong>Example</strong>: A startup using AWS Lambda to process user-uploaded images dynamically.</li></ul><h4>5. Domain-Driven Design (DDD)</h4><p>Focuses on aligning software design with business logic and goals. Often paired with Microservices for tackling complex systems.</p><ul><li><strong>Example</strong>: A logistics company using DDD to model shipping routes and inventory management.</li></ul><h4>🔄 <strong>Summing It Up</strong></h4><p>Solution Architecture is more than just technical know-how; it’s a craft that requires creativity, strategy, and a deep understanding of business needs. By understanding its history and evolution, architects can better appreciate the modern methodologies that have redefined how we approach software design.</p><p>💡 <em>“The goal of architecture isn’t to build a perfect system; it’s to build a system perfect for its purpose.”</em> — Anonymous</p><h4>🔜 Next in the Series</h4><p>In our next blog, we’ll dive deep into <strong>Monolithic Architecture</strong> — how it shaped early software development and why it remains relevant for specific use cases today. <em>The next post is tentatively scheduled for two weeks from now</em>. Check the comments for the link once it’s live. Stay tuned!</p><h4>💬 Share Your Thoughts!</h4><p>Thanks for reading! If you found this blog useful, please leave a clap 👏 and share it with your network. We value your feedback, so feel free to drop your thoughts in the comments 💬 below. If there are any specific methodologies you’d like to see covered in this series, let us know! Constructive feedback is always welcome.</p><p>Thank you for reading, and see you in the next post! 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b77de372a45" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/unlocking-the-power-of-solution-architecture-a-guide-to-methodologies-for-modern-systems-5b77de372a45">🚀 Unlocking the Power of Solution Architecture: A Guide to Methodologies for Modern Systems</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Architecting for Scale: Key Event-Driven Patterns You Need to Know]]></title>
            <link>https://levelup.gitconnected.com/architecting-for-scale-key-event-driven-patterns-you-need-to-know-71599fb4e62c?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/71599fb4e62c</guid>
            <category><![CDATA[microservices-pattern]]></category>
            <category><![CDATA[real-time-processing]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Thu, 07 Nov 2024 01:20:23 GMT</pubDate>
            <atom:updated>2024-11-07T01:20:23.170Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Comprehensive Guide to Event-Driven Architectural Patterns</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*NixhOaPOTu-KckZkW5o9UQ.png" /></figure><p>In today’s landscape of distributed systems and microservices, <strong>Event-Driven Architecture (EDA)</strong> has emerged as a powerful approach for building responsive, scalable, and resilient applications. By decoupling services and leveraging asynchronous communication, EDA makes it easier to handle complex workflows and unpredictable workloads. This guide dives into essential patterns in event-driven architecture and explores their use cases, along with practical tools for implementation.</p><blockquote>“The success of a distributed system lies in its ability to handle events effectively, allowing the system to grow organically and adapt to change.” — Anonymous</blockquote><h3>🧩 What is Event-Driven Architecture?</h3><p>Event-Driven Architecture revolves around <strong>events</strong> — notifications of state changes that are emitted by one component (producer) and processed by another (consumer). By decoupling event producers from consumers, systems can handle high loads and remain responsive. This asynchronous approach enables scalability and flexibility, especially in distributed environments where services need to interact efficiently.</p><h4>Core Concepts of EDA</h4><p>In EDA, three primary roles facilitate communication:</p><ol><li><strong>Event Producers</strong>: These components generate and emit events whenever a change or action occurs. For example, an e-commerce site’s order system might produce an event when a new order is placed.</li><li><strong>Event Routers/Brokers</strong>: Middleware or brokers (like Kafka or RabbitMQ) distribute the events to relevant consumers. They handle the transport, routing, and potential storage of events, ensuring they reach their intended destination.</li><li><strong>Event Consumers</strong>: These are components or services that consume events to perform actions or trigger workflows. In the e-commerce example, a shipping service might consume the order event to initiate the packaging and delivery process.</li></ol><p>The three main types of EDA are:</p><ul><li><strong>Simple Event Processing</strong>: Basic pattern where events are simply tracked without complex handling.</li><li><strong>Event Stream Processing</strong>: Involves continuous flow and real-time processing of event data.</li><li><strong>Complex Event Processing (CEP)</strong>: Analyzes patterns across multiple event streams to detect intricate conditions and trigger complex workflows.</li></ul><h3>How Event-Driven Architecture Works</h3><p>Here’s a step-by-step breakdown of how EDA operates:</p><ol><li><strong>Event Occurrence</strong>: When something meaningful happens in the system, such as a user action or system trigger, an event is created by the producer. This event contains data and metadata to describe the occurrence.</li><li><strong>Event Emission</strong>: The event is emitted and published to an event router or broker. The router typically provides infrastructure that reliably stores, routes, and forwards events to registered consumers.</li><li><strong>Event Routing and Processing</strong>: The broker routes the event to interested consumers. Some architectures also involve filters or message queues to manage how events are distributed.</li><li><strong>Consumer Response</strong>: Consumers process the event, triggering actions or workflows. For example, an analytics service might log the event for trend analysis, while another service updates related systems. Once processed, some events can initiate new workflows, creating a chain of reactions throughout the architecture.</li><li><strong>Event-Driven Workflow</strong>: In complex cases, multiple services may collaborate, using events as triggers to work together, handle failures, and maintain consistency across distributed transactions.</li></ol><h3>Core Event-Driven Patterns</h3><h4>🔹 Competing Consumer Pattern</h4><p>The <strong>Competing Consumer Pattern</strong> allows multiple consumers to process events from a shared queue, distributing the load among them. Consumers compete to handle events as they arrive, balancing the workload and enhancing throughput by allowing parallel processing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*HXfcE18JJJvOs_huX5ChEw.png" /></figure><p><strong><em>📌 Example</em></strong></p><p>In a <strong>Competing Consumer</strong> pattern for video encoding, uploaded videos are added to a queue as encoding tasks. Multiple encoding services (consumers) then retrieve and process these tasks concurrently, balancing the workload and speeding up overall processing times. This setup ensures faster, efficient handling of high video upload volumes.</p><p><strong>🎯<em> Use Cases:</em></strong></p><ul><li><strong>Task Processing</strong>: Distributing tasks like video encoding or data processing.</li><li><strong>Load Balancing</strong>: Managing heavy workloads by spreading them across multiple instances.</li></ul><p><strong>🛠️<em> Tools:</em></strong></p><ul><li><a href="https://www.rabbitmq.com/"><strong>RabbitMQ</strong></a>: An effective message broker for implementing competing consumers.</li><li><a href="https://aws.amazon.com/sqs/"><strong>Amazon SQS</strong></a>: A fully managed queuing service for horizontal scaling.</li></ul><h4>🔹 Consume and Project Pattern</h4><p>In this pattern, the system <strong>consumes events</strong> and <strong>projects</strong> the data into new formats or aggregated models. This is useful for transforming raw data into meaningful insights, ready for analysis or further action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*_wkvvxwKm-9MBEmHgMk3GQ.png" /></figure><p><strong><em>📌 Example</em></strong></p><p>In the <strong>Consume and Project</strong> pattern, when an order is created, the <strong>Order Service</strong> emits an <strong>Order Creation</strong> event. The <strong>Order Projection Service</strong> consumes this event, updating a materialized view with enriched order data for fast, optimized access. Additionally, the <strong>Order Projection Service</strong> sends enriched data to the <strong>Customer Service</strong>, which updates the <strong>Customer Database</strong> with new order-related details, like recent purchase history, enhancing the customer’s profile for future interactions. This enables efficient data transformation and streamlined updates across services.</p><p><strong>🎯<em> Use Cases:</em></strong></p><ul><li><strong>Data Transformation</strong>: Making raw data usable for reporting.</li><li><strong>Real-Time Analytics</strong>: Providing aggregated data for dashboards and insights.</li></ul><p><strong>🛠️<em> Tools:</em></strong></p><ul><li><a href="https://kafka.apache.org/documentation/streams/"><strong>Kafka Streams</strong></a>: A stream-processing library that allows for data transformation.</li><li><a href="https://flink.apache.org/"><strong>Apache Flink</strong></a>: A robust engine for real-time stream processing and projection.</li></ul><h4>🔹 Event Sourcing Pattern</h4><p><strong>Event Sourcing</strong> involves capturing each change to a system as an event, allowing the system’s state to be reconstructed by replaying the entire event history. This pattern offers full traceability and enables the rebuilding of the system state at any time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*rVplfAd9TxaU3p8DA8gbqg.png" /></figure><p><strong><em>📌 Example</em></strong></p><p>In the <strong>Event Sourcing</strong> pattern, every change to an order’s state is stored as an event, creating an auditable history. For example, when an order is placed, an <strong>Order Created</strong> event is saved, recording initial details. As the order progresses, an <strong>Order Shipped</strong> event is logged, capturing shipping information. If the order is later canceled, an <strong>Order Canceled</strong> event is added. By replaying these events, the system can reconstruct the order’s history or current state at any time, ensuring a clear, traceable record.</p><p><strong>🎯 <em>Use Cases:</em></strong></p><ul><li><strong>Auditing</strong>: Keeping a complete history of all events for traceability.</li><li><strong>State Reconstruction</strong>: Rebuilding current state from event history if needed.</li></ul><p><strong>🛠️ <em>Tools:</em></strong></p><ul><li><a href="https://www.eventstore.com/"><strong>EventStoreDB</strong></a>: A database built specifically for event sourcing.</li><li><a href="https://axoniq.io/"><strong>Axon Framework</strong></a>: Supports event sourcing and distributed event handling.</li></ul><h4>🔹 Async Task Execution Pattern</h4><p>The <strong>Async Task Execution Pattern</strong> is ideal for offloading time-consuming or resource-intensive tasks to be processed in the background. This ensures that the main application remains responsive while secondary tasks run asynchronously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*RykYqlv443dIfWmt6O2zJA.png" /></figure><p><strong><em>📌 Example</em></strong></p><p>In an <strong>Async Task Execution</strong> pattern for an e-commerce site, tasks like payment processing, inventory updates, and order confirmation are handled asynchronously after a user places an order. This allows the site to remain fast and responsive for the user, while background services complete each step independently.</p><p><strong>🎯<em> Use Cases:</em></strong></p><ul><li><strong>Non-blocking Operations</strong>: Handling long-running tasks without blocking the main workflow.</li><li><strong>Background Processing</strong>: For tasks like sending emails, generating reports, or data processing.</li></ul><p>🛠<strong><em>️ Tools:</em></strong></p><ul><li><a href="https://aws.amazon.com/lambda/"><strong>AWS Lambda</strong></a>: Executes functions asynchronously in response to events.</li><li><a href="https://docs.celeryq.dev/en/stable/getting-started/introduction.html"><strong>Celery</strong></a>: A Python distributed task queue for handling asynchronous tasks.</li></ul><h4>🔹 Transactional Outbox Pattern</h4><p>The <strong>Transactional Outbox Pattern</strong> ensures data consistency when publishing events by using a transactional “outbox” table. Events are stored in the outbox table within the same transaction as the primary data, then sent to consumers only after a successful commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*TePXJBkqFfnaWiiMsZWTmQ.png" /></figure><p><strong><em>📌 Example</em></strong></p><p>In a <strong>Transactional Outbox</strong> pattern for an order management system, when an order is recorded, a corresponding event is stored in an outbox within the same transaction. Once the transaction is successfully committed, the event is published to notify inventory and shipping services, ensuring data consistency across all services.</p><p><strong>🎯<em> Use Cases:</em></strong></p><ul><li><strong>Consistent Event Publishing</strong>: Ensuring that events are published reliably.</li><li><strong>Microservice Synchronization</strong>: Maintaining consistency across distributed services.</li></ul><p><strong>🛠<em>️ Tools:</em></strong></p><ul><li><a href="https://debezium.io/"><strong>Debezium</strong></a>: Captures database changes and synchronizes them with Kafka.</li><li><a href="https://docs.confluent.io/platform/current/connect/index.html"><strong>Kafka Connect</strong></a>: Publishes events from an outbox table to Kafka topics.</li></ul><h4>🔹 Event Aggregation Pattern</h4><p>The <strong>Event Aggregation Pattern</strong> gathers and combines multiple events, producing a single event for further processing. This is useful for cases where actions are based on the outcome of multiple related events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*w3XqAmw-pTm1pFKCezgs-A.png" /></figure><p><strong><em>📌 Example</em></strong></p><p>In an <strong>Event Aggregator</strong> setup for customer creation, a single <strong>Create Customer</strong> event is split into three finer events: <strong>Create Contact</strong>, <strong>Create Account</strong>, and <strong>Create Address</strong>. Each event is handled by a specialized service, which processes its part independently — adding contact details, setting up the account, and recording the address. The Event Aggregator consolidates these events, ensuring all parts are complete before confirming the customer creation. This allows for modular, reliable processing across services.</p><p><strong>🎯<em> Use Cases:</em></strong></p><ul><li><strong>Cross-Service Workflow</strong>: Aggregating data from multiple services to trigger workflows.</li><li><strong>Real-Time Monitoring</strong>: Combining log events for unified insights.</li></ul><p><strong>🛠<em>️ Tools:</em></strong></p><ul><li><a href="https://aws.amazon.com/step-functions/"><strong>AWS Step Functions</strong></a>: Enables event aggregation for orchestrating workflows.</li><li><a href="https://flink.apache.org/"><strong>Apache Flink</strong></a>: A real-time stream processor for event aggregation.</li></ul><h4>🔹 Saga Pattern</h4><p>The <strong>Saga Pattern</strong> manages distributed transactions by breaking them into a sequence of smaller, isolated steps. Each step emits an event and, in the event of failure, triggers compensating actions to maintain data consistency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*MfRSJgJLiPxfvDtSZhCVjg.png" /></figure><p><strong><em>📌 Example</em></strong></p><p>In an e-commerce system, the <strong>Saga Pattern</strong> coordinates the order process across multiple services. First, the <strong>Order Service</strong> creates the order, storing it in the database and triggering the <strong>Saga Orchestrator</strong>. The orchestrator then sends a payment command to the <strong>Payment Service</strong> and, upon completion, initiates shipping through the <strong>Shipping Service</strong>. Finally, once the order is shipped, the saga updates the order status in the database. This approach ensures smooth, consistent transaction flow and handles any failures with compensating actions.</p><p><strong>🎯<em> Use Cases:</em></strong></p><ul><li><strong>Distributed Transactions</strong>: Coordinating transactions across multiple services.</li><li><strong>Fault Tolerance</strong>: Maintaining consistency even when certain operations fail.</li></ul><p><strong>🛠<em>️ Tools:</em></strong></p><ul><li><a href="https://axoniq.io/"><strong>Axon Framework</strong></a>: Supports the implementation of sagas with event-driven systems.</li><li><a href="https://camunda.com/"><strong>Camunda</strong></a>: A workflow engine for managing complex transactions.</li></ul><h3>🎯 Real-World Use Cases for Event-Driven Architecture</h3><ol><li><strong>E-Commerce</strong>: Retail platforms use <strong>Competing Consumer</strong> and <strong>Async Task Execution Patterns</strong> to handle large volumes of orders while maintaining system responsiveness.</li><li><strong>Financial Services</strong>: Banks leverage <strong>Event Sourcing</strong> and <strong>Saga Patterns</strong> to ensure transaction integrity and traceability across multiple systems.</li><li><strong>IoT Systems</strong>: Smart homes and industrial IoT platforms utilize <strong>Event Aggregation</strong> to process and analyze sensor data in real time.</li><li><strong>Travel and Booking</strong>: Travel applications rely on <strong>Transactional Outbox</strong> and <strong>Saga Patterns</strong> to ensure all booking components (flights, hotels, rentals) are synchronized and consistent.</li></ol><h3>📈 Pros and Cons of Event-Driven Architecture</h3><h4>Pros of EDA</h4><ol><li><strong>Scalability</strong>: EDA supports distributed and microservices architectures, making it easy to scale individual services based on demand.</li><li><strong>Resilience and Fault Tolerance</strong>: EDA minimizes tight coupling, meaning that the failure of one component often does not directly impact others. Event routers can buffer events if consumers are temporarily unavailable, enhancing fault tolerance.</li><li><strong>Asynchronous Processing</strong>: Events enable background processing, allowing the system to handle user requests promptly without waiting for downstream tasks to complete. This leads to lower latency and a more responsive user experience.</li><li><strong>Flexibility and Extensibility</strong>: New event consumers or services can be added without changing the event producers, making it easy to expand the system and integrate additional capabilities.</li><li><strong>Real-Time Data Processing</strong>: For applications requiring real-time insights (e.g., analytics, monitoring), EDA enables continuous processing and immediate response to events.</li></ol><h4>Cons of EDA</h4><ol><li><strong>Increased Complexity</strong>: EDA introduces additional architectural complexity with more components and the need for coordination between services. This can complicate both development and debugging.</li><li><strong>Difficulty in Ensuring Data Consistency</strong>: In distributed systems, consistency is challenging to maintain, especially in cases where events are processed out of order or duplicated.</li><li><strong>Latency in Event Delivery</strong>: While EDA can reduce application latency, certain events may still experience delays in being delivered or processed, especially in large systems with many consumers.</li><li><strong>Error Handling and Event Management</strong>: Handling failures and ensuring all events are processed correctly requires careful management. Some architectures (like Saga or compensating transactions) address this, but it increases complexity.</li><li><strong>Potential for Data Duplication</strong>: With many services producing and consuming events independently, there’s a risk of duplicating data, leading to inefficiencies if not carefully managed.</li><li><strong>Testing and Debugging Challenges</strong>: Asynchronous and distributed environments can be challenging to troubleshoot, with many moving parts to monitor and test.</li></ol><h3>🔍 Conclusion</h3><p>Event-driven architecture offers a powerful model for modern applications needing scalability, flexibility, and fault tolerance. By implementing key patterns like <strong>Competing Consumer</strong>, <strong>Event Sourcing</strong>, and <strong>Saga</strong>, organizations can build systems that respond effectively to real-time events while maintaining data integrity and consistency. However, careful consideration is required to manage complexity and ensure effective event handling.</p><h3>🛠️ References</h3><ul><li><a href="https://www.eventstore.com/">EventStoreDB</a></li><li><a href="https://axoniq.io/">Axon Framework</a></li><li><a href="https://www.rabbitmq.com/">RabbitMQ</a></li><li><a href="https://kafka.apache.org/">Kafka</a></li><li><a href="https://aws.amazon.com/lambda/">AWS Lambda</a></li><li><a href="https://debezium.io/">Debezium</a></li></ul><blockquote>“Learning never exhausts the mind; it only expands it.” — <em>Leonardo da Vinci</em></blockquote><p>Thanks for reading! I hope this exploration into Event-Driven Architecture patterns added value to your journey. Feel free to share your thoughts, ask questions, or leave constructive feedback 💬below. And if you enjoyed this, a clap 👏 is always appreciated!</p><blockquote>Keep learning, keep growing.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71599fb4e62c" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/architecting-for-scale-key-event-driven-patterns-you-need-to-know-71599fb4e62c">Architecting for Scale: Key Event-Driven Patterns You Need to Know</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Discord Stores TRILLIONS of Messages]]></title>
            <link>https://mohammedvaghjipurwala.medium.com/how-discord-stores-trillions-of-messages-27906ef2a6ff?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/27906ef2a6ff</guid>
            <category><![CDATA[scylladb]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[database-migration]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[high-availability]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Tue, 29 Oct 2024 03:30:37 GMT</pubDate>
            <atom:updated>2024-10-29T03:30:37.509Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>A Colossal Database Migration: Discord’s Journey from Cassandra to ScyllaDB</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*mdYzP6htH1cZfnoVc1WetQ.png" /></figure><p><strong>Introduction:</strong></p><p>In this blog post, we will delve into the remarkable database migration journey undertaken by Discord engineers, involving the transfer of trillions of messages from Cassandra to ScyllaDB. If you’ve ever wondered about the challenges of migrating data at such an unimaginable scale, get ready for an exciting story of innovative engineering and clever solutions.</p><p><strong>The Predicament with Cassandra:</strong></p><p>As Discord’s platform continued to grow, they encountered serious performance issues with Cassandra, their chosen database. The maintenance of the main Cassandra cluster holding messages became increasingly cumbersome, leading to unpredictable latency and frequent on-call incidents that strained the team’s resources.</p><p>By 2022, the Cassandra cluster housed trillions of messages across 177 nodes, making it clear that a change was necessary. Discord’s very foundation depended on the efficiency of the message cluster. Therefore, finding a robust solution was critical.</p><p><strong>The Solution: Embracing ScyllaDB:</strong></p><p>The solution to Discord’s database dilemma was ScyllaDB, a powerful C++-based engine compatible with Cassandra. However, instead of jumping straight into tackling the colossal task, the engineers opted for a gradual approach. They began with smaller database migrations to test the waters and address any potential issues before diving into the massive migration of trillions of messages.</p><p><strong>The Intermediate Layer: Introducing Data Services:</strong></p><p>To optimize its database architecture, Discord created an intermediate layer called Data Services between the API monolith and the database clusters. This layer, built using the Rust programming language, introduced the concept of request coalescing. It allowed multiple users requesting the same data to be served with a single database query, reducing the chances of hot partitions and enhancing performance.</p><p><strong>The Superdisk Innovation:</strong></p><p>To tackle disk latency challenges, Discord had to innovate beyond the limitations of local NVMe SSDs on virtual machines. They chose to prioritize low-latency disk reads while maintaining high durability for critical data storage. The result was the creation of a unique “super disk,” a two-layered RAID solution. By combining RAID0 to merge multiple local SSDs into a low-latency virtual disk and RAID1 to mirror this array with a persistent disk, Discord achieved an optimized solution tailored to their specific needs.</p><p><strong>The Migration Journey:</strong></p><p>With all preparations in place, Discord embarked on the migration of their largest database, the ‘Cassandra-messages’ cluster, comprising trillions of messages and nearly 200 nodes. However, with a newly developed data migrator in Rust and clever strategies, the team pulled off the migration in just nine days! Astonishingly, they accomplished this without any downtime, completing the migration of trillions of messages in less than two weeks.</p><p><strong>The Reward:</strong></p><p>The migration to ScyllaDB resulted in a significantly quieter and more efficient system. Discord reduced the number of nodes from 177 Cassandra nodes to just 72 ScyllaDB nodes, leading to improved latencies and a better quality of life for the on-call staff. This extraordinary task was achieved through clever risk mitigation and the implementation of innovative solutions.</p><p><strong>Conclusion:</strong></p><p>Discord’s colossal database migration from Cassandra to ScyllaDB is a testament to the power of careful planning, gradual implementation, and out-of-the-box thinking. It showcases the prowess of a dynamic and innovative engineering culture that thrives on tackling challenges head-on. Migrating a production database at this scale is no small feat, and Discord’s success in accomplishing it is truly commendable.</p><p><strong>References :</strong></p><ul><li><a href="https://discord.com/blog/how-discord-stores-trillions-of-messages">https://discord.com/blog/how-discord-stores-trillions-of-messages</a></li><li><a href="https://www.youtube.com/watch?v=O3PwuzCvAjI">https://www.youtube.com/watch?v=O3PwuzCvAjI</a></li></ul><p>If you found this blog useful do leave a clap 👏 or comment 💬 . Any feedback or constructive criticism is welcomed 🙌.</p><p>You can reach out to me on <a href="https://in.linkedin.com/in/mohammed-vaghjipurwala-aab561b9">LinkedIn</a> or <a href="https://twitter.com/mohammedhv">Twitter</a> or in the comment section below.</p><blockquote><em>Happy Coding ..!!! 💻</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27906ef2a6ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID Principles to write a better code]]></title>
            <link>https://medium.com/geekculture/solid-principles-to-write-a-better-code-8aa5bf3c589?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aa5bf3c589</guid>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[better-coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Wed, 05 Apr 2023 01:01:50 GMT</pubDate>
            <atom:updated>2023-04-05T01:02:49.683Z</atom:updated>
            <content:encoded><![CDATA[<h4>A quick guide to writing better code with help of the SOLID Design Principles, illustrated with Python examples.</h4><blockquote>Any fool can write code that a computer can understand. Good programmers write code that humans can understand — Martin Fowler</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ioAxEdLcHhKM31BE" /><figcaption>Photo by <a href="https://unsplash.com/@jstrippa?utm_source=medium&amp;utm_medium=referral">James Harrison</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>MY CODE WORKS — WHY DOES IT NEED TO BE BETTER?</h4><ul><li>It’s easy to hack together solutions and move on to the next problem — and in a perfect world, where we could just write code and forget about it, perhaps that would’ve been acceptable. However, code tends to evolve over time; we come back to it to modify it, tweak it, and fix bugs — and well-designed code is much easier to come back to. Bad code becomes harder and harder to maintain, slowing down development efforts. Good code comes with future benefits.</li><li>Also, bad code can easily have side effects; and side effects mean that you can make a change in one place, only to cause a hard-to-find bug somewhere else, resulting in a painful debugging exercise. It’s much harder for bugs to hide in well-designed, easy-to-read code.</li></ul><h4>So, What is SOLID?</h4><p>The principle of SOLID is an acronym originated by Robert C. Martin. SOLID refers to a set of principles of Object Oriented Programming and Design. These principles are intended to help developers to write maintainable, extensible code. The principles are as follows</p><ol><li><strong>S</strong>ingle Responsibility Principle</li><li><strong>O</strong>pen/Closed Principle</li><li><strong>L</strong>iskov Substitution Principle</li><li><strong>I</strong>nterface Segregation Principle</li><li><strong>D</strong>ependency Inversion Principle</li></ol><p>Let‘s explore each principle in detail</p><h4>1. Single Responsibility Principle</h4><blockquote>A class should do one thing and therefore it should have only a single reason to change</blockquote><p>In other words, every component of your code (in general a class, but also a function) should have <em>one and only one responsibility and it should perform the task efficiently</em>. As a consequence of that, there should be only a reason to change it.</p><p>Following the Single Responsibility Principle (SRP) is important. First of all, because many different teams can work on the same project and edit the same class for different reasons, this could lead to incompatible modules.</p><p>Second, it makes version control easier. For example, say we have a persistence class that handles database operations, and we see a change in that file in the GitHub commits. By following the SRP, we will know that it is related to storage or database-related stuff.</p><p>Merge conflicts are another example. They appear when different teams change the same file. But if the SRP is followed, fewer conflicts will appear — files will have a single reason to change, and conflicts that do exist will be easier to resolve.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520Album%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520name%25252C%252520artist%25252C%252520songs%2529%252520-%25253E%252520None%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.name%252520%25253D%252520name%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.artist%252520%25253D%252520artist%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.songs%252520%25253D%252520songs%25250A%252520%252520%252520%252520def%252520add_song%2528self%25252C%252520song%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.songs.append%2528song%2529%25250A%252520%252520%252520%252520def%252520remove_song%2528self%25252C%252520song%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.songs.remove%2528song%2529%252520%25250A%252520%252520%252520%252520def%252520__str__%2528self%2529%252520-%25253E%252520str%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520f%252522Album%252520%25257Bself.name%25257D%252520by%252520%25257Bself.artist%25257D%25255CnTracklist%25253A%25255Cn%25257Bself.songs%25257D%252522%25250A%252520%252520%252520%252520%252523%252520breaks%252520the%252520SRP%25250A%252520%252520%252520%252520def%252520search_album_by_artist%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252522%252522%252522%252520Searching%252520the%252520database%252520for%252520other%252520albums%252520by%252520same%252520artist%252520%252522%252522%252522%25250A%252520%252520%252520%252520%252520%252520%252520%252520pass&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520Album%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520name%2525252C%25252520artist%2525252C%25252520songs%252529%25252520-%2525253E%25252520None%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.name%25252520%2525253D%25252520name%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.artist%25252520%2525253D%25252520artist%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.songs%25252520%2525253D%25252520songs%2525250A%25252520%25252520%25252520%25252520def%25252520add_song%252528self%2525252C%25252520song%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.songs.append%252528song%252529%2525250A%25252520%25252520%25252520%25252520def%25252520remove_song%252528self%2525252C%25252520song%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.songs.remove%252528song%252529%25252520%2525250A%25252520%25252520%25252520%25252520def%25252520__str__%252528self%252529%25252520-%2525253E%25252520str%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520f%25252522Album%25252520%2525257Bself.name%2525257D%25252520by%25252520%2525257Bself.artist%2525257D%2525255CnTracklist%2525253A%2525255Cn%2525257Bself.songs%2525257D%25252522%2525250A%25252520%25252520%25252520%25252520%25252523%25252520breaks%25252520the%25252520SRP%2525250A%25252520%25252520%25252520%25252520def%25252520search_album_by_artist%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522%25252522%25252522%25252520Searching%25252520the%25252520database%25252520for%25252520other%25252520albums%25252520by%25252520same%25252520artist%25252520%25252522%25252522%25252522%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520pass&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2daa82b0b1f570c52beebbb423943fdb/href">https://medium.com/media/2daa82b0b1f570c52beebbb423943fdb/href</a></iframe><p>In the above example, We have a class Album. This stores the album name, artist, and track list, and can manipulate the contents of the album, such as adding songs or deleting them. Now, if I add a function to search albums from the same artist, It breaks the Single Responsibility Principle. Album class would have to change if we decide to store albums in a different way (for example by adding the record label or storing the track list as a dictionary of track name and length), and Album class would also need to change if we change the database to store these albums ( for example moving to an online database from an Excel sheet). It is clear that these are two distinct responsibilities.<br>Instead, We should create a different class for interacting with the Albums database. This could be expanded by searching albums by starting letters, number of tracks, etc.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520AlbumBrowser%25253A%25250A%252520%252520%252520%252520%252522%252522%252522%252520Class%252520for%252520browsing%252520the%252520Albums%252520database%252522%252522%252522%25250A%252520%252520%252520%252520def%252520search_album_by_artist%2528self%25252C%252520albums%25252C%252520artist%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520...%25250A%252520%252520%252520%252520%25250A%252520%252520%252520%252520def%252520search_album_starting_with_letter%2528self%25252C%252520albums%25252C%252520letter%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520...&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520AlbumBrowser%2525253A%2525250A%25252520%25252520%25252520%25252520%25252522%25252522%25252522%25252520Class%25252520for%25252520browsing%25252520the%25252520Albums%25252520database%25252522%25252522%25252522%2525250A%25252520%25252520%25252520%25252520def%25252520search_album_by_artist%252528self%2525252C%25252520albums%2525252C%25252520artist%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520...%2525250A%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520def%25252520search_album_starting_with_letter%252528self%2525252C%25252520albums%2525252C%25252520letter%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520...&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1baaf64ef3848149a89571f57cbf0d3/href">https://medium.com/media/e1baaf64ef3848149a89571f57cbf0d3/href</a></iframe><p><em>Note:</em> Oversimplifying the class will make the code lengthy and make it hard to follow the long chain of objects being passed between different components and may lead to code fragmentation. This principle does not literally mean for each class to do <em>one single thing </em>as in one method but as <em>one concept</em>.</p><h4>2. Open/Closed Principle</h4><blockquote>classes should be open for extension and closed for modification.</blockquote><p>Modification means changing the code of an existing class, and extension means adding new functionality.</p><p>This principle states that We should be able to add new functionality without touching the existing code for the class. This is because whenever we modify the existing code, we are taking the risk of creating potential bugs. So we should avoid touching the tested and reliable (mostly) production code if possible.</p><p>If this principle is not followed, the result could be a long list of changes in depending classes, regression on existing features, and unnecessary hours of testing.</p><p>Let’s use the same Example</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520Album%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520name%25252C%252520artist%25252C%252520songs%25252C%252520genre%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.name%252520%25253D%252520name%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.artist%252520%25253D%252520artist%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.songs%252520%25253D%252520songs%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.genre%252520%25253D%252520genre%25250A%25250A%25250Aclass%252520AlbumBrowser%25253A%25250A%252520%252520%252520%252520def%252520search_album_by_artist%2528self%25252C%252520albums%25252C%252520artist%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520%25255Balbum%252520for%252520album%252520in%252520albums%252520if%252520album.artist%252520%25253D%25253D%252520artist%25255D%25250A%252520%252520%252520%252520def%252520search_album_by_genre%2528self%25252C%252520albums%25252C%252520genre%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520%25255Balbum%252520for%252520album%252520in%252520albums%252520if%252520album.genre%252520%25253D%25253D%252520genre%25255D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520Album%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520name%2525252C%25252520artist%2525252C%25252520songs%2525252C%25252520genre%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.name%25252520%2525253D%25252520name%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.artist%25252520%2525253D%25252520artist%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.songs%25252520%2525253D%25252520songs%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.genre%25252520%2525253D%25252520genre%2525250A%2525250A%2525250Aclass%25252520AlbumBrowser%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520search_album_by_artist%252528self%2525252C%25252520albums%2525252C%25252520artist%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520%2525255Balbum%25252520for%25252520album%25252520in%25252520albums%25252520if%25252520album.artist%25252520%2525253D%2525253D%25252520artist%2525255D%2525250A%25252520%25252520%25252520%25252520def%25252520search_album_by_genre%252528self%2525252C%25252520albums%2525252C%25252520genre%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520%2525255Balbum%25252520for%25252520album%25252520in%25252520albums%25252520if%25252520album.genre%25252520%2525253D%2525253D%25252520genre%2525255D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/56e20d02fc81b3365cd65b9842e1c010/href">https://medium.com/media/56e20d02fc81b3365cd65b9842e1c010/href</a></iframe><p>Now, Let‘s say We want to search <em>by artist and genre </em>What if we plan to add the <em>release year</em>? We’ll have to write a new function every time (in total (2^n)-1 to be precise), and the number grows exponentially.</p><p>Instead, We should define a base class with a common interface for the specification, and then define subclasses for each type of specification that inherits this interface from the base class</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%252523after%25250Aclass%252520SearchBy%25253A%25250A%252520%252520%252520%252520def%252520is_matched%2528self%25252C%252520album%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520pass%25250A%252520%252520%252520%252520%252520%252520%25250Aclass%252520SearchByGenre%2528SearchBy%2529%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520genre%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.genre%252520%25253D%252520genre%25250A%252520%252520%252520%252520def%252520is_matched%2528self%25252C%252520album%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520album.genre%252520%25253D%25253D%252520self.genre%25250A%252520%252520%252520%252520%25250Aclass%252520SearchByArtist%2528SearchBy%2529%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520artist%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.artist%252520%25253D%252520artist%25250A%252520%252520%252520%252520def%252520is_matched%2528self%25252C%252520album%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520album.artist%252520%25253D%25253D%252520self.artist%25250A%252520%252520%252520%252520%25250Aclass%252520AlbumBrowser%25253A%25250A%252520%252520%252520%252520def%252520browse%2528self%25252C%252520albums%25252C%252520searchby%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520%25255Balbum%252520for%252520album%252520in%252520albums%252520if%252520searchby.is_matched%2528album%2529%25255D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%25252523after%2525250Aclass%25252520SearchBy%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520is_matched%252528self%2525252C%25252520album%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520pass%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%2525250Aclass%25252520SearchByGenre%252528SearchBy%252529%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520genre%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.genre%25252520%2525253D%25252520genre%2525250A%25252520%25252520%25252520%25252520def%25252520is_matched%252528self%2525252C%25252520album%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520album.genre%25252520%2525253D%2525253D%25252520self.genre%2525250A%25252520%25252520%25252520%25252520%2525250Aclass%25252520SearchByArtist%252528SearchBy%252529%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520artist%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.artist%25252520%2525253D%25252520artist%2525250A%25252520%25252520%25252520%25252520def%25252520is_matched%252528self%2525252C%25252520album%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520album.artist%25252520%2525253D%2525253D%25252520self.artist%2525250A%25252520%25252520%25252520%25252520%2525250Aclass%25252520AlbumBrowser%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520browse%252528self%2525252C%25252520albums%2525252C%25252520searchby%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520%2525255Balbum%25252520for%25252520album%25252520in%25252520albums%25252520if%25252520searchby.is_matched%252528album%252529%2525255D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0741a7308863ed6ea095adecb1e689f0/href">https://medium.com/media/0741a7308863ed6ea095adecb1e689f0/href</a></iframe><p>This allows us to extend the searches with another class when we want (e.g. by release date). Any new search class will need to satisfy the interface defined by Searchby, so we won’t have surprises when interacting with our existing code. To browse by the search by criteria, we now need to create a SearchBy object first and pass that into AlbumBrowser.</p><p>But what about multiple criteria? For This, we can use &amp; for join browsing criteria to be joined together</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%252523add%252520__and__%25253A%25250Aclass%252520SearchBy%25253A%25250A%252520%252520%252520%252520def%252520is_matched%2528self%25252C%252520album%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520pass%25250A%252520%252520%252520%252520%25250A%252520%252520%252520%252520def%252520__and__%2528self%25252C%252520other%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520AndSearchBy%2528self%25252C%252520other%2529%25250Aclass%252520AndSearchBy%2528SearchBy%2529%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520searchby1%25252C%252520searchby2%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.searchby1%252520%25253D%252520searchby1%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.searchby2%252520%25253D%252520searchby2%25250A%252520%252520%252520%252520def%252520is_matched%2528self%25252C%252520album%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520self.searchby1.is_matched%2528album%2529%252520and%252520self.searchby2.is_matched%2528album%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%25252523add%25252520__and__%2525253A%2525250Aclass%25252520SearchBy%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520is_matched%252528self%2525252C%25252520album%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520pass%2525250A%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520def%25252520__and__%252528self%2525252C%25252520other%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520AndSearchBy%252528self%2525252C%25252520other%252529%2525250Aclass%25252520AndSearchBy%252528SearchBy%252529%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520searchby1%2525252C%25252520searchby2%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.searchby1%25252520%2525253D%25252520searchby1%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.searchby2%25252520%2525253D%25252520searchby2%2525250A%25252520%25252520%25252520%25252520def%25252520is_matched%252528self%2525252C%25252520album%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520self.searchby1.is_matched%252528album%252529%25252520and%25252520self.searchby2.is_matched%252528album%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e3220aef200e9b7877919795cdcb61a/href">https://medium.com/media/6e3220aef200e9b7877919795cdcb61a/href</a></iframe><p>This &amp; method can be a bit confusing, so the following example demonstrates its usage:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3DLAWoman%252520%25253D%252520Album%2528%25250A%252520%252520%252520%252520name%25253D%252522L.A.%252520Woman%252522%25252C%25250A%252520%252520%252520%252520artist%25253D%252522The%252520Doors%252522%25252C%25250A%252520%252520%252520%252520songs%25253D%25255B%252522Riders%252520on%252520the%252520Storm%252522%25255D%25252C%25250A%252520%252520%252520%252520genre%25253D%252522Rock%252522%25252C%25250A%2529%25250ATrash%252520%25253D%252520Album%2528%25250A%252520%252520%252520%252520name%25253D%252522Trash%252522%25252C%25250A%252520%252520%252520%252520artist%25253D%252522Alice%252520Cooper%252522%25252C%25250A%252520%252520%252520%252520songs%25253D%25255B%252522Poison%252522%25255D%25252C%25250A%252520%252520%252520%252520genre%25253D%252522Rock%252522%25252C%25250A%2529%25250Aalbums%252520%25253D%252520%25255BLAWoman%25252C%252520Trash%25255D%25250A%252523%252520this%252520creates%252520the%252520AndSearchBy%252520object%25250Amy_search_criteria%252520%25253D%252520SearchByGenre%2528genre%25253D%252522Rock%252522%2529%252520%252526%252520SearchByArtist%2528%25250A%252520%252520%252520%252520artist%25253D%252522The%252520Doors%252522%25250A%2529%25250Abrowser%252520%25253D%252520AlbumBrowser%2528%2529%25250Aassert%252520browser.browse%2528albums%25253Dalbums%25252C%252520searchby%25253Dmy_search_criteria%2529%252520%25253D%25253D%252520%25255BLAWoman%25255D%25250A%252523%252520yay%252520we%252520found%252520our%252520album&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3DLAWoman%25252520%2525253D%25252520Album%252528%2525250A%25252520%25252520%25252520%25252520name%2525253D%25252522L.A.%25252520Woman%25252522%2525252C%2525250A%25252520%25252520%25252520%25252520artist%2525253D%25252522The%25252520Doors%25252522%2525252C%2525250A%25252520%25252520%25252520%25252520songs%2525253D%2525255B%25252522Riders%25252520on%25252520the%25252520Storm%25252522%2525255D%2525252C%2525250A%25252520%25252520%25252520%25252520genre%2525253D%25252522Rock%25252522%2525252C%2525250A%252529%2525250ATrash%25252520%2525253D%25252520Album%252528%2525250A%25252520%25252520%25252520%25252520name%2525253D%25252522Trash%25252522%2525252C%2525250A%25252520%25252520%25252520%25252520artist%2525253D%25252522Alice%25252520Cooper%25252522%2525252C%2525250A%25252520%25252520%25252520%25252520songs%2525253D%2525255B%25252522Poison%25252522%2525255D%2525252C%2525250A%25252520%25252520%25252520%25252520genre%2525253D%25252522Rock%25252522%2525252C%2525250A%252529%2525250Aalbums%25252520%2525253D%25252520%2525255BLAWoman%2525252C%25252520Trash%2525255D%2525250A%25252523%25252520this%25252520creates%25252520the%25252520AndSearchBy%25252520object%2525250Amy_search_criteria%25252520%2525253D%25252520SearchByGenre%252528genre%2525253D%25252522Rock%25252522%252529%25252520%25252526%25252520SearchByArtist%252528%2525250A%25252520%25252520%25252520%25252520artist%2525253D%25252522The%25252520Doors%25252522%2525250A%252529%2525250Abrowser%25252520%2525253D%25252520AlbumBrowser%252528%252529%2525250Aassert%25252520browser.browse%252528albums%2525253Dalbums%2525252C%25252520searchby%2525253Dmy_search_criteria%252529%25252520%2525253D%2525253D%25252520%2525255BLAWoman%2525255D%2525250A%25252523%25252520yay%25252520we%25252520found%25252520our%25252520album&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0aa8112d80ece44df11f91bbf6ecc411/href">https://medium.com/media/0aa8112d80ece44df11f91bbf6ecc411/href</a></iframe><h4>3. Liskov Substitution Principle</h4><p>This principle was formulated by Barbara Liskov and states that</p><blockquote>subclasses should be substitutable for their base classes.</blockquote><p>This means that, given that class B is a subclass of class A, we should be able to pass an object of class B to any method that expects an object of class A and the method should not give any weird output in that case.</p><p>This is the expected behavior because when we use inheritance we assume that the child class inherits everything that the superclass has. The child class extends the behavior but never narrows it down.</p><p>Therefore, when a class does not obey this principle, it leads to some nasty bugs that are hard to detect.</p><p>In the classic example with rectangles and squares, we create a Rectangle class, with width and height setters. If you have a square, the width setter also needs to resize the height, and vice versa to keep the square property. This forces us to make a choice: we either keep the implementation of the Rectangle class, but then Square stops being a square when you use the setter on it, or you change the setters to make height and width the same for squares. This could lead to some unexpected behavior if you have a function that resizes the height of your shape.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520Rectangle%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520height%25252C%252520width%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self._height%252520%25253D%252520height%25250A%252520%252520%252520%252520%252520%252520%252520%252520self._width%252520%25253D%252520width%25250A%252520%252520%252520%252520%252540property%25250A%252520%252520%252520%252520def%252520width%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520self._width%25250A%252520%252520%252520%252520%252540width.setter%25250A%252520%252520%252520%252520def%252520width%2528self%25252C%252520value%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self._width%252520%25253D%252520value%25250A%252520%252520%252520%252520%252540property%25250A%252520%252520%252520%252520def%252520height%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520self._height%25250A%252520%252520%252520%252520%252540height.setter%25250A%252520%252520%252520%252520def%252520height%2528self%25252C%252520value%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self._height%252520%25253D%252520value%25250A%252520%252520%252520%252520def%252520get_area%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520self._width%252520%252A%252520self._height&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520Rectangle%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520height%2525252C%25252520width%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self._height%25252520%2525253D%25252520height%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self._width%25252520%2525253D%25252520width%2525250A%25252520%25252520%25252520%25252520%25252540property%2525250A%25252520%25252520%25252520%25252520def%25252520width%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520self._width%2525250A%25252520%25252520%25252520%25252520%25252540width.setter%2525250A%25252520%25252520%25252520%25252520def%25252520width%252528self%2525252C%25252520value%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self._width%25252520%2525253D%25252520value%2525250A%25252520%25252520%25252520%25252520%25252540property%2525250A%25252520%25252520%25252520%25252520def%25252520height%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520self._height%2525250A%25252520%25252520%25252520%25252520%25252540height.setter%2525250A%25252520%25252520%25252520%25252520def%25252520height%252528self%2525252C%25252520value%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self._height%25252520%2525253D%25252520value%2525250A%25252520%25252520%25252520%25252520def%25252520get_area%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520self._width%25252520%25252A%25252520self._height&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/11faa4268dec925fe2b5eebe880fa637/href">https://medium.com/media/11faa4268dec925fe2b5eebe880fa637/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520Square%2528Rectangle%2529%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520size%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520Rectangle.__init__%2528self%25252C%252520size%25252C%252520size%2529%25250A%252520%252520%252520%252520%252540Rectangle.width.setter%25250A%252520%252520%252520%252520def%252520width%2528self%25252C%252520value%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self._width%252520%25253D%252520value%25250A%252520%252520%252520%252520%252520%252520%252520%252520self._height%252520%25253D%252520value%25250A%252520%252520%252520%252520%252540Rectangle.height.setter%25250A%252520%252520%252520%252520def%252520height%2528self%25252C%252520value%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self._width%252520%25253D%252520value%25250A%252520%252520%252520%252520%252520%252520%252520%252520self._height%252520%25253D%252520value&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520Square%252528Rectangle%252529%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520size%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520Rectangle.__init__%252528self%2525252C%25252520size%2525252C%25252520size%252529%2525250A%25252520%25252520%25252520%25252520%25252540Rectangle.width.setter%2525250A%25252520%25252520%25252520%25252520def%25252520width%252528self%2525252C%25252520value%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self._width%25252520%2525253D%25252520value%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self._height%25252520%2525253D%25252520value%2525250A%25252520%25252520%25252520%25252520%25252540Rectangle.height.setter%2525250A%25252520%25252520%25252520%25252520def%25252520height%252528self%2525252C%25252520value%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self._width%25252520%2525253D%25252520value%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self._height%25252520%2525253D%25252520value&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/275aa455415f76276fdafbca4d56032d/href">https://medium.com/media/275aa455415f76276fdafbca4d56032d/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Ddef%252520get_squashed_height_area%2528Rectangle%2529%25253A%25250A%252520%252520%252520%252520Rectangle.height%252520%25253D%2525201%25250A%252520%252520%252520%252520area%252520%25253D%252520Rectangle.get_area%2528%2529%25250A%252520%252520%252520%252520return%252520area%25250Arectangle%252520%25253D%252520Rectangle%25285%25252C%2525205%2529%25250Asquare%252520%25253D%252520Square%25285%2529%25250Aassert%252520get_squashed_height_area%2528rectangle%2529%252520%25253D%25253D%2525205%252520%252520%252523%252520expected%2525205%25250Aassert%252520get_squashed_height_area%2528square%2529%252520%25253D%25253D%2525201%252520%252520%252523%252520expected%2525205&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Ddef%25252520get_squashed_height_area%252528Rectangle%252529%2525253A%2525250A%25252520%25252520%25252520%25252520Rectangle.height%25252520%2525253D%252525201%2525250A%25252520%25252520%25252520%25252520area%25252520%2525253D%25252520Rectangle.get_area%252528%252529%2525250A%25252520%25252520%25252520%25252520return%25252520area%2525250Arectangle%25252520%2525253D%25252520Rectangle%2525285%2525252C%252525205%252529%2525250Asquare%25252520%2525253D%25252520Square%2525285%252529%2525250Aassert%25252520get_squashed_height_area%252528rectangle%252529%25252520%2525253D%2525253D%252525205%25252520%25252520%25252523%25252520expected%252525205%2525250Aassert%25252520get_squashed_height_area%252528square%252529%25252520%2525253D%2525253D%252525201%25252520%25252520%25252523%25252520expected%252525205&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a13a0a0ed84407f83503bb748814fab/href">https://medium.com/media/8a13a0a0ed84407f83503bb748814fab/href</a></iframe><p>While this might not look like a big deal (surely you can just remember square changes the width too?!), this becomes a bigger issue when the functions are more complicated or when you are using someone else’s code, and just assume the subclass behaves the same.</p><h4>4. Interface Segregation Principle</h4><blockquote>Many client-specific interfaces are better than one general-purpose interface. Clients should not be forced to implement a function they do not need.</blockquote><p>Segregation means keeping things separated, and the Interface Segregation Principle is about separating the interfaces.</p><p>If you have a base class with many methods, possibly not all of your subclasses are going to need them, maybe just a few. But due to inheritance, you will be able to call these methods on all the subclasses, even on those that don’t need it. This means a lot of interfaces that are unused, and unneeded and will result in bugs when they get accidentally called.</p><p>This principle is meant to prevent this from happening. We should make interfaces as small as possible so that we don’t need to implement functions we don’t need. Instead of one big base class, we should split them into multiple ones. They should only have methods that make sense for each and then have our subclasses inherit from them.</p><p>In the next example, we will be using abstract methods. Abstract methods create an interface in a base class that has no implementation but is forced to be implemented in every subclass that inherits from the base class. Abstract methods are essentially enforcing an interface.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520PlaySongs%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520title%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.title%252520%25253D%252520title%25250A%252520%252520%252520%252520def%252520play_drums%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522Ba-dum%252520ts%252522%2529%25250A%252520%252520%252520%252520def%252520play_guitar%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522%252ASoul-moving%252520guitar%252520solo%252A%252522%2529%25250A%252520%252520%252520%252520def%252520sing_lyrics%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522NaNaNaNa%252522%2529%25250A%252523%252520This%252520class%252520is%252520fine%25252C%252520just%252520changing%252520the%252520guitar%252520and%252520lyrics%25250Aclass%252520PlayRockSongs%2528PlaySongs%2529%25253A%252520%25250A%252520%252520%252520%252520def%252520play_guitar%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522%252AVery%252520metal%252520guitar%252520solo%252A%252522%2529%25250A%252520%252520%252520%252520def%252520sing_lyrics%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522I%252520wanna%252520rock%252520and%252520roll%252520all%252520night%252522%2529%25250A%252523%252520This%252520breaks%252520the%252520ISP%25252C%252520we%252520don%2527t%252520have%252520lyrics%252520%25250Aclass%252520PlayInstrumentalSongs%2528PlaySongs%2529%25253A%25250A%252520%252520%252520%252520def%252520sing_lyrics%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520raise%252520Exception%2528%252522No%252520lyrics%252520for%252520instrumental%252520songs%252522%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520PlaySongs%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520title%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.title%25252520%2525253D%25252520title%2525250A%25252520%25252520%25252520%25252520def%25252520play_drums%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522Ba-dum%25252520ts%25252522%252529%2525250A%25252520%25252520%25252520%25252520def%25252520play_guitar%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522%25252ASoul-moving%25252520guitar%25252520solo%25252A%25252522%252529%2525250A%25252520%25252520%25252520%25252520def%25252520sing_lyrics%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522NaNaNaNa%25252522%252529%2525250A%25252523%25252520This%25252520class%25252520is%25252520fine%2525252C%25252520just%25252520changing%25252520the%25252520guitar%25252520and%25252520lyrics%2525250Aclass%25252520PlayRockSongs%252528PlaySongs%252529%2525253A%25252520%2525250A%25252520%25252520%25252520%25252520def%25252520play_guitar%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522%25252AVery%25252520metal%25252520guitar%25252520solo%25252A%25252522%252529%2525250A%25252520%25252520%25252520%25252520def%25252520sing_lyrics%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522I%25252520wanna%25252520rock%25252520and%25252520roll%25252520all%25252520night%25252522%252529%2525250A%25252523%25252520This%25252520breaks%25252520the%25252520ISP%2525252C%25252520we%25252520don%252527t%25252520have%25252520lyrics%25252520%2525250Aclass%25252520PlayInstrumentalSongs%252528PlaySongs%252529%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520sing_lyrics%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520raise%25252520Exception%252528%25252522No%25252520lyrics%25252520for%25252520instrumental%25252520songs%25252522%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3295631136301f6d46393dfac266ba44/href">https://medium.com/media/3295631136301f6d46393dfac266ba44/href</a></iframe><p>Instead, we could have a class for the singing and the music separately (assuming guitar and drums always happen together in our case, otherwise we need to split them up even more, perhaps by instrument.) This way, we only have the interfaces we need, we cannot call sing lyrics on instrumental songs.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfrom%252520abc%252520import%252520ABCMeta%25250Aclass%252520PlaySongsLyrics%25253A%25250A%252520%252520%252520%252520%252540abstractmethod%25250A%252520%252520%252520%252520def%252520sing_lyrics%2528self%25252C%252520title%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520pass%25250Aclass%252520PlaySongsMusic%25253A%25250A%252520%252520%252520%252520%252540abstractmethod%25250A%252520%252520%252520%252520def%252520play_guitar%2528self%25252C%252520title%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520pass%25250A%252520%252520%252520%252520%252540abstractmethod%25250A%252520%252520%252520%252520def%252520play_drums%2528self%25252C%252520title%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520pass%25250Aclass%252520PlayInstrumentalSong%2528PlaySongsMusic%2529%25253A%25250A%252520%252520%252520%252520def%252520play_drums%2528self%25252C%252520title%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522Ba-dum%252520ts%252522%2529%25250A%252520%252520%252520%252520def%252520play_guitar%2528self%25252C%252520title%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522%252ASoul-moving%252520guitar%252520solo%252A%252522%2529%25250Aclass%252520PlayRockSong%2528PlaySongsMusic%25252C%252520PlaySongsLyrics%2529%25253A%25250A%252520%252520%252520%252520def%252520play_guitar%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522%252AVery%252520metal%252520guitar%252520solo%252A%252522%2529%25250A%252520%252520%252520%252520def%252520sing_lyrics%2528self%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522I%252520wanna%252520rock%252520and%252520roll%252520all%252520night%252522%2529%25250A%252520%252520%252520%252520def%252520play_drums%2528self%25252C%252520title%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520print%2528%252522Ba-dum%252520ts%252522%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfrom%25252520abc%25252520import%25252520ABCMeta%2525250Aclass%25252520PlaySongsLyrics%2525253A%2525250A%25252520%25252520%25252520%25252520%25252540abstractmethod%2525250A%25252520%25252520%25252520%25252520def%25252520sing_lyrics%252528self%2525252C%25252520title%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520pass%2525250Aclass%25252520PlaySongsMusic%2525253A%2525250A%25252520%25252520%25252520%25252520%25252540abstractmethod%2525250A%25252520%25252520%25252520%25252520def%25252520play_guitar%252528self%2525252C%25252520title%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520pass%2525250A%25252520%25252520%25252520%25252520%25252540abstractmethod%2525250A%25252520%25252520%25252520%25252520def%25252520play_drums%252528self%2525252C%25252520title%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520pass%2525250Aclass%25252520PlayInstrumentalSong%252528PlaySongsMusic%252529%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520play_drums%252528self%2525252C%25252520title%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522Ba-dum%25252520ts%25252522%252529%2525250A%25252520%25252520%25252520%25252520def%25252520play_guitar%252528self%2525252C%25252520title%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522%25252ASoul-moving%25252520guitar%25252520solo%25252A%25252522%252529%2525250Aclass%25252520PlayRockSong%252528PlaySongsMusic%2525252C%25252520PlaySongsLyrics%252529%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520play_guitar%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522%25252AVery%25252520metal%25252520guitar%25252520solo%25252A%25252522%252529%2525250A%25252520%25252520%25252520%25252520def%25252520sing_lyrics%252528self%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522I%25252520wanna%25252520rock%25252520and%25252520roll%25252520all%25252520night%25252522%252529%2525250A%25252520%25252520%25252520%25252520def%25252520play_drums%252528self%2525252C%25252520title%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528%25252522Ba-dum%25252520ts%25252522%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/39634ea27f692ed75ff8e32bf5d84162/href">https://medium.com/media/39634ea27f692ed75ff8e32bf5d84162/href</a></iframe><p>Now our model is much more flexible and extendable, and the clients do not need to implement any irrelevant logic.</p><h4>5. Dependency Inversion Principle</h4><blockquote>Our classes should depend upon interfaces or abstract classes instead of concrete classes and functions.</blockquote><p>In his <a href="https://fi.ort.edu.uy/innovaportal/file/2032/1/design_principles.pdf">article </a>(2000), Uncle Bob summarizes this principle as follows:</p><p><em>“If the Open/Closed Principle states the goal of Object Oriented architecture, then Dependency Inversion Principle states the primary mechanism”.</em></p><p>In other words, <em>High-level modules should not depend on low-level modules. Both should depend on abstractions (e.g. interfaces).</em></p><p><em>Abstractions should not depend on details. Details (concrete implementations) should depend on abstractions.</em></p><p>If your code has well-defined abstract interfaces, changing the internal implementation of one class shouldn’t break your code. A class it interacts with should not have knowledge of the inner workings of the other class, and should be unaffected as long as the interfaces are the same. An example would be changing the type of database you use (SQL or NoSQL) or changing the data structure you store your data in (dictionary or list).</p><p>This is illustrated in the following example, where ViewRockAlbums explicitly depends on the fact that albums are stored in a tuple in a certain order inside AlbumStore. It should have no knowledge of the internal structure of Albumstore. Now if we change the ordering in the tuples in the album, our code would break.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520AlbumStore%25253A%25250A%252520%252520%252520%252520albums%252520%25253D%252520%25255B%25255D%25250A%252520%252520%252520%252520def%252520add_album%2528self%25252C%252520name%25252C%252520artist%25252C%252520genre%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.albums.append%2528%2528name%25252C%252520artist%25252C%252520genre%2529%2529%25250Aclass%252520ViewRockAlbums%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520album_store%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520for%252520album%252520in%252520album_store.albums%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520if%252520album%25255B2%25255D%252520%25253D%25253D%252520%252522Rock%252522%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520print%2528f%252522We%252520have%252520%25257Balbum%25255B0%25255D%25257D%252520in%252520store.%252522%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520AlbumStore%2525253A%2525250A%25252520%25252520%25252520%25252520albums%25252520%2525253D%25252520%2525255B%2525255D%2525250A%25252520%25252520%25252520%25252520def%25252520add_album%252528self%2525252C%25252520name%2525252C%25252520artist%2525252C%25252520genre%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.albums.append%252528%252528name%2525252C%25252520artist%2525252C%25252520genre%252529%252529%2525250Aclass%25252520ViewRockAlbums%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520album_store%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520for%25252520album%25252520in%25252520album_store.albums%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520if%25252520album%2525255B2%2525255D%25252520%2525253D%2525253D%25252520%25252522Rock%25252522%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528f%25252522We%25252520have%25252520%2525257Balbum%2525255B0%2525255D%2525257D%25252520in%25252520store.%25252522%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1bdc5738a0d10c9ddbb542c7b26d28d/href">https://medium.com/media/a1bdc5738a0d10c9ddbb542c7b26d28d/href</a></iframe><p>Instead, we need to add an abstract interface to AlbumStore to hide the details, that can be called by other classes. This should be done as in the example in the Open-Closed Principle, but assuming we don’t care about filtering by anything else, I’ll just add a filter_by_genre method. Now if we had another type of AlbumStore, that decides to store the album differently, it would need to implement the same interface for filter_by_genre to make ViewRockAlbums work.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520GeneralAlbumStore%25253A%25250A%252520%252520%252520%252520%252540abstractmethod%25250A%252520%252520%252520%252520def%252520filter_by_genre%2528self%25252C%252520genre%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520pass%25250Aclass%252520MyAlbumStore%2528GeneralAlbumStore%2529%25253A%25250A%252520%252520%252520%252520albums%252520%25253D%252520%25255B%25255D%25250A%252520%252520%252520%252520def%252520add_album%2528self%25252C%252520name%25252C%252520artist%25252C%252520genre%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520self.albums.append%2528%2528name%25252C%252520artist%25252C%252520genre%2529%2529%25250A%252520%252520%252520%252520def%252520filter_by_genre%2528self%25252C%252520genre%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520if%252520album%25255B2%25255D%252520%25253D%25253D%252520genre%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520yield%252520album%25255B0%25255D%25250Aclass%252520ViewRockAlbums%25253A%25250A%252520%252520%252520%252520def%252520__init__%2528self%25252C%252520album_store%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520for%252520album_name%252520in%252520album_store.filter_by_genre%2528%252522Rock%252522%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520print%2528f%252522We%252520have%252520%25257Balbum_name%25257D%252520in%252520store.%252522%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmonokai%26wt%3Dnone%26l%3Dpython%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520GeneralAlbumStore%2525253A%2525250A%25252520%25252520%25252520%25252520%25252540abstractmethod%2525250A%25252520%25252520%25252520%25252520def%25252520filter_by_genre%252528self%2525252C%25252520genre%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520pass%2525250Aclass%25252520MyAlbumStore%252528GeneralAlbumStore%252529%2525253A%2525250A%25252520%25252520%25252520%25252520albums%25252520%2525253D%25252520%2525255B%2525255D%2525250A%25252520%25252520%25252520%25252520def%25252520add_album%252528self%2525252C%25252520name%2525252C%25252520artist%2525252C%25252520genre%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520self.albums.append%252528%252528name%2525252C%25252520artist%2525252C%25252520genre%252529%252529%2525250A%25252520%25252520%25252520%25252520def%25252520filter_by_genre%252528self%2525252C%25252520genre%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520if%25252520album%2525255B2%2525255D%25252520%2525253D%2525253D%25252520genre%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520yield%25252520album%2525255B0%2525255D%2525250Aclass%25252520ViewRockAlbums%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520__init__%252528self%2525252C%25252520album_store%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520for%25252520album_name%25252520in%25252520album_store.filter_by_genre%252528%25252522Rock%25252522%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520print%252528f%25252522We%25252520have%25252520%2525257Balbum_name%2525257D%25252520in%25252520store.%25252522%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/29d0464fed17842280bb1fa74145e893/href">https://medium.com/media/29d0464fed17842280bb1fa74145e893/href</a></iframe><h4>Benefits of applying SOLID Principles</h4><ul><li>Encourages good code-level design.</li><li>Drives consistency in design.</li><li>Increases cohesion in classes.</li><li>Reduce Coupling between classes.</li><li>Reduce the likelihood of breaking changes.</li><li>Simplifies debugging.</li><li>Simplifies Code maintenance.</li><li>Simplifies Unit testing.</li></ul><h4>Potential Offenders of SOLID Principles</h4><ul><li>Utility Classes (i.e. where everyone puts all the functions they don’t want to think about).</li><li>User Interfaces where business logic is built on the UI layer.</li><li>Classes that become massive ‘<em>GOD Objects</em>’ containing most business logic for an entire application.</li><li>Code that is written in such a way that it has to do explicit instanceOf checks before operating on objects.</li></ul><h4>Conclusion</h4><p>The SOLID design principles are meant to be a guideline to write maintainable, expandable, and easy-to-understand code. It is worth keeping them in mind next time you think of a design, to write SOLID code.</p><blockquote>Good Design adds value faster than it adds cost</blockquote><blockquote>— Thomas.C.Gale</blockquote><h4>References</h4><ol><li>The SOLID Principles of Object-Oriented Programming Explained in Plain English — <a href="https://www.freecodecamp.org/news/solid-principles-explained-in-plain-english/">https://www.freecodecamp.org/news/solid-principles-explained-in-plain-english/</a></li><li>Udemy Course — <a href="https://www.udemy.com/course/1-hour-crash-course-using-solid-to-write-better-code/">https://www.udemy.com/course/1-hour-crash-course-using-solid-to-write-better-code/</a></li></ol><p>If you found this blog useful do leave a clap 👏 or comment 💬 . Any feedback or constructive criticism is welcomed 🙌.</p><p>You can reach out to me on <a href="https://in.linkedin.com/in/mohammed-vaghjipurwala-aab561b9">LinkedIn</a> or <a href="https://twitter.com/mohammedhv">Twitter</a> or in the comment section below.</p><blockquote><em>Happy Coding ..!!! 💻</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aa5bf3c589" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/solid-principles-to-write-a-better-code-8aa5bf3c589">SOLID Principles to write a better code</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Source Code Obfuscation]]></title>
            <link>https://medium.com/geekculture/python-source-code-obfuscation-6b97f88a460d?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b97f88a460d</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[cython]]></category>
            <category><![CDATA[intellectual-property]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[obfuscation]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Fri, 24 Dec 2021 16:31:09 GMT</pubDate>
            <atom:updated>2021-12-24T16:31:09.072Z</atom:updated>
            <content:encoded><![CDATA[<h4>Enciphering your Python Code to avoid Reverse Engineering.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VkS8agGt5schHU1KWRIlTw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@maurosbicego?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Mauro Sbicego</a> on <a href="https://unsplash.com/s/photos/encryption?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>In software development, <strong>Obfuscation</strong> is the deliberate act of creating Source Code that is difficult for humans to understand. The Code is often obfuscated to protect intellectual property or trade secrets, and to prevent an attacker from <em>reverse engineering</em> a proprietary software program.</blockquote><p><em>Encrypting some or all of a program’s code is one obfuscation method.</em></p><p>In Python, There are multiple packages available using which you can obfuscate your code base and secure your intellectual property.</p><ul><li><a href="https://pypi.org/project/pyarmor/"><strong>pyarmor</strong></a> — full obfuscation with hex-encoding; apparently doesn’t allow partial obfuscation of variable/function names only.</li><li><a href="https://pypi.org/project/python-minifier/"><strong>python-minifier</strong></a> — minifies the code and obfuscates function/variable names.</li><li><a href="https://pypi.org/project/pyminifier/"><strong>pyminifier</strong></a> — does a good job in obfuscating names of functions, variables, literals; can also perform hex-encoding (compression) similar as pyarmor. Problem: after obfuscation the code may contain syntax errors and not run.</li></ul><p>While researching, I found another option to obfuscate my Python Code using <a href="https://cython.org/">Cython</a> which was quite useful and difficult to Reverse Engineer.</p><p><em>Obfuscation</em> <em>is one of the many features Cython package provides</em>. Cython is an <strong>optimizing static compiler </strong>that takes your .py modules and translates them to high-performant C files. Resulting C files can be compiled into native binary libraries with no effort. When the compilation is done there’s no way to reverse compiled libraries back to readable Python source code.</p><p>Let me walk you through steps towards Python source code obfuscation using Cython. We’ll use a Simple project to Showcase the same.</p><h4>Sample Code to Demonstrate the Code Obfuscation</h4><p>I have written a small python Flask based code which takes <em>numeric equation </em>as an Input, validates the equation and if valid, resolved the equation. Nothing Logical, just for tutorial purpose. The idea is to showcase the code obfuscation of the business logic.</p><h4>Code Base</h4><ul><li><a href="https://github.com/mohammedvaghjipurwala/code_obfuscation">https://github.com/mohammedvaghjipurwala/code_obfuscation</a></li></ul><p>The Code repo looks like…</p><pre>.<br>├── README.md<br>├── __init__.py<br>├── main.py<br>├── routes.py<br>├── swagger.yml<br>├── src<br>│   ├── __init__.py<br>│   └── solver.py<br>└── compile.py</pre><h4>Code Walk-through</h4><ul><li>main.py : This file is the flask bootstrap file through which the flask app starts.</li><li>routes.py : This file hosts all the API routes provided by the application</li><li>swagger.yml : This file hosts the API Details which can be accessed in the form of formatted documentation via Browser.</li><li>src/solver.py : This file hosts the business logic of verifying the equation and if valid, then solving the equation.</li><li>compile.py : This file hosts the code base to build the .so files from the .py files.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%25250A%252523%252520This%252520program%252520builds%252520.so%252520files%252520from%252520.py%252520files%25250A%252523%252520and%252520delete%252520%2527.py%2527%25252C%252520%2527.c%2527%252520and%252520%2527.pyc%2527%252520files.%252523%252520install%252520cpython%25253A%25250A%252523%252520sudo%252520pip%252520install%252520cython%25250A%252523%252520Command%252520to%252520run%252520build%25253A%25250A%252523%252520python%252520compile.py%252520build_ext%252520--inplace%25250A%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%252523%25250A%25250Aimport%252520os%25250Aimport%252520sys%25250Afrom%252520distutils.core%252520import%252520setup%25250Afrom%252520distutils.extension%252520import%252520Extension%25250Afrom%252520pathlib%252520import%252520Path%25250A%25250Afrom%252520Cython.Build%252520import%252520cythonize%25250A%25250A%252523%252520Get%252520current%252520folder%252520path%25250Amash_path%252520%25253D%252520os.path.dirname%2528sys.argv%25255B0%25255D%2529%25250A%25250A%252523%252523%252523%252520Get%252520.py%252520files%25250Aextensions%252520%25253D%252520%25255B%25255D%25250Aexcludefiles%252520%25253D%252520%25255B%2527compile%2527%25252C%252520%2527__init__%2527%25252C%252520%2527main%2527%25252C%252520%2527routes%2527%25255D%25250A%25250A%252523%252523%252523%252520build%252520.so%252520files%252520from%252520.py%252520files%252520%252523%252523%252523%25250Afor%252520file%252520in%252520list%2528Path%2528mash_path%2529.glob%2528%2527%252A%252A%25252F%252A.py%2527%2529%2529%25253A%25250A%252520%252520%252520%252520%252523%252520Take%252520out%252520file%252520name%252520without%252520.py%252520ext%25250A%252520%252520%252520%252520filename%252520%25253D%252520Path%2528file%2529.resolve%2528%2529.stem%25250A%252520%252520%252520%252520if%252520file.stat%2528%2529.st_size%252520%2521%25253D%2525200%252520and%252520filename%252520not%252520in%252520excludefiles%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520relpath%252520%25253D%252520os.path.relpath%2528os.path.dirname%2528file.absolute%2528%2529.as_posix%2528%2529%2529%25252C%252520mash_path%2529%25250A%252520%252520%252520%252520%252520%252520%252520%252520packagename%252520%25253D%252520relpath.replace%2528%2527%25252F%2527%25252C%252520%2527.%2527%2529%252520%25252B%252520%2527.%2527%252520%25252B%252520filename%252520if%252520relpath%252520%2521%25253D%252520%2527.%2527%252520else%252520filename%25250A%252520%252520%252520%252520%252520%252520%252520%252520extensions.append%2528%25255BExtension%2528packagename%25252C%252520%25255Bstr%2528file%2529%25255D%2529%25255D%2529%25250A%25250Afor%252520ext%252520in%252520extensions%25253A%25250A%252520%252520%252520%252520setup%2528ext_modules%25253Dcythonize%2528ext%25252C%252520compiler_directives%25253D%25257B%25250A%252520%252520%252520%252520%252520%252520%252520%252520%2527c_string_type%2527%25253A%252520%2527str%2527%25252C%25250A%252520%252520%252520%252520%252520%252520%252520%252520%2527c_string_encoding%2527%25253A%252520%2527utf8%2527%25252C%25250A%252520%252520%252520%252520%252520%252520%252520%252520%2527language_level%2527%25253A%2525203%25257D%2529%2529%25250A%25250Adef%252520deletefiles%2528file_type%2529%25253A%25250A%252520%252520%252520%252520cfiles%252520%25253D%252520list%2528Path%2528mash_path%2529.glob%2528%2527%252A%252A%25252F%252A.%2527%252520%25252B%252520file_type%2529%2529%25250A%252520%252520%252520%252520for%252520cfile%252520in%252520cfiles%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520filename%252520%25253D%252520Path%2528cfile%2529.resolve%2528%2529.stem%25250A%252520%252520%252520%252520%252520%252520%252520%252520if%252520filename%252520not%252520in%252520excludefiles%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520cfile.unlink%2528%2529%25250A%25250A%252523%252523%252523%252520delete%252520%252A.py%252520files%252520%252523%252523%252523%25250Adeletefiles%2528%2527py%2527%2529%25250A%25250A%252523%252523%252523%252520delete%252520%252A.c%252520files%252520%252523%252523%252523%252523%252523%25250Adeletefiles%2528%2527c%2527%2529%25250A%25250A%252523%252523%252523%252520delete%252520%252A.pyc%252520files%252520%252523%252523%252523%252523%252523%25250Adeletefiles%2528%2527pyc%2527%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%2525250A%25252523%25252520This%25252520program%25252520builds%25252520.so%25252520files%25252520from%25252520.py%25252520files%2525250A%25252523%25252520and%25252520delete%25252520%252527.py%252527%2525252C%25252520%252527.c%252527%25252520and%25252520%252527.pyc%252527%25252520files.%25252523%25252520install%25252520cpython%2525253A%2525250A%25252523%25252520sudo%25252520pip%25252520install%25252520cython%2525250A%25252523%25252520Command%25252520to%25252520run%25252520build%2525253A%2525250A%25252523%25252520python%25252520compile.py%25252520build_ext%25252520--inplace%2525250A%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%25252523%2525250A%2525250Aimport%25252520os%2525250Aimport%25252520sys%2525250Afrom%25252520distutils.core%25252520import%25252520setup%2525250Afrom%25252520distutils.extension%25252520import%25252520Extension%2525250Afrom%25252520pathlib%25252520import%25252520Path%2525250A%2525250Afrom%25252520Cython.Build%25252520import%25252520cythonize%2525250A%2525250A%25252523%25252520Get%25252520current%25252520folder%25252520path%2525250Amash_path%25252520%2525253D%25252520os.path.dirname%252528sys.argv%2525255B0%2525255D%252529%2525250A%2525250A%25252523%25252523%25252523%25252520Get%25252520.py%25252520files%2525250Aextensions%25252520%2525253D%25252520%2525255B%2525255D%2525250Aexcludefiles%25252520%2525253D%25252520%2525255B%252527compile%252527%2525252C%25252520%252527__init__%252527%2525252C%25252520%252527main%252527%2525252C%25252520%252527routes%252527%2525255D%2525250A%2525250A%25252523%25252523%25252523%25252520build%25252520.so%25252520files%25252520from%25252520.py%25252520files%25252520%25252523%25252523%25252523%2525250Afor%25252520file%25252520in%25252520list%252528Path%252528mash_path%252529.glob%252528%252527%25252A%25252A%2525252F%25252A.py%252527%252529%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252523%25252520Take%25252520out%25252520file%25252520name%25252520without%25252520.py%25252520ext%2525250A%25252520%25252520%25252520%25252520filename%25252520%2525253D%25252520Path%252528file%252529.resolve%252528%252529.stem%2525250A%25252520%25252520%25252520%25252520if%25252520file.stat%252528%252529.st_size%25252520%252521%2525253D%252525200%25252520and%25252520filename%25252520not%25252520in%25252520excludefiles%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520relpath%25252520%2525253D%25252520os.path.relpath%252528os.path.dirname%252528file.absolute%252528%252529.as_posix%252528%252529%252529%2525252C%25252520mash_path%252529%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520packagename%25252520%2525253D%25252520relpath.replace%252528%252527%2525252F%252527%2525252C%25252520%252527.%252527%252529%25252520%2525252B%25252520%252527.%252527%25252520%2525252B%25252520filename%25252520if%25252520relpath%25252520%252521%2525253D%25252520%252527.%252527%25252520else%25252520filename%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520extensions.append%252528%2525255BExtension%252528packagename%2525252C%25252520%2525255Bstr%252528file%252529%2525255D%252529%2525255D%252529%2525250A%2525250Afor%25252520ext%25252520in%25252520extensions%2525253A%2525250A%25252520%25252520%25252520%25252520setup%252528ext_modules%2525253Dcythonize%252528ext%2525252C%25252520compiler_directives%2525253D%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%252527c_string_type%252527%2525253A%25252520%252527str%252527%2525252C%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%252527c_string_encoding%252527%2525253A%25252520%252527utf8%252527%2525252C%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%252527language_level%252527%2525253A%252525203%2525257D%252529%252529%2525250A%2525250Adef%25252520deletefiles%252528file_type%252529%2525253A%2525250A%25252520%25252520%25252520%25252520cfiles%25252520%2525253D%25252520list%252528Path%252528mash_path%252529.glob%252528%252527%25252A%25252A%2525252F%25252A.%252527%25252520%2525252B%25252520file_type%252529%252529%2525250A%25252520%25252520%25252520%25252520for%25252520cfile%25252520in%25252520cfiles%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520filename%25252520%2525253D%25252520Path%252528cfile%252529.resolve%252528%252529.stem%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520if%25252520filename%25252520not%25252520in%25252520excludefiles%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520cfile.unlink%252528%252529%2525250A%2525250A%25252523%25252523%25252523%25252520delete%25252520%25252A.py%25252520files%25252520%25252523%25252523%25252523%2525250Adeletefiles%252528%252527py%252527%252529%2525250A%2525250A%25252523%25252523%25252523%25252520delete%25252520%25252A.c%25252520files%25252520%25252523%25252523%25252523%25252523%25252523%2525250Adeletefiles%252528%252527c%252527%252529%2525250A%2525250A%25252523%25252523%25252523%25252520delete%25252520%25252A.pyc%25252520files%25252520%25252523%25252523%25252523%25252523%25252523%2525250Adeletefiles%252528%252527pyc%252527%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8ba176a9031530ec292a8ded7114ef7/href">https://medium.com/media/d8ba176a9031530ec292a8ded7114ef7/href</a></iframe><h4>Code Execution</h4><p>To run the Flask application execute the below command in the terminal</p><pre>python main.py</pre><p>Now you can access the Swagger API Documentation using the URL</p><pre>http://&lt;public-ip&gt;/ui</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A7byH9M_seeBtTZPud8mkw.png" /><figcaption>Swagger</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gj2ZSJSl12VLXA5_gnH-kA.png" /><figcaption>Success Response</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ji2nfRZla-T2oczXvzIUZA.png" /><figcaption>Error Response</figcaption></figure><h4>Run compile.py</h4><p>Depending on the Python version you use, run:</p><pre>python compile.py build_ext --inplace</pre><p>…or, for Python 3:</p><pre>python3 compile.py build_ext --inplace</pre><p>The above command will generate .so and .c files next to your .py source files:</p><pre>.<br>├── README.md<br>├── __init__.py<br>├── main.py<br>├── routes.py<br>├── swagger.yml<br>├── src<br>│   ├── __init__.py<br>│   ├── solver.py<br>│   ├── solver.c<br>│   └── solver.cpython-37m-x86_64-linux-gnu.so<br>└── compile.py</pre><p>The .c files are intermediate sources used to generate .so files, which are binary modules you want to distribute. When building on Windows these files will probably have the .pyd extension.</p><p>You can delete .pyc, .c and .py files after a successful build and keep the .so files only. A method has been added for the same.</p><p>Note that .so-files contain the target platform in their names (e.g. darwin on my MacOS). Obviously, the compiled modules are not cross-platform. If you distribute your program to Ubuntu Linux users, you should compile it on Linux. Otherwise you won’t be able to load these binaries. So you’ll have to compile a platform-specific version of your code for each of your targeted platforms.</p><p>The trigger of this script can be added in the setup files or Dockerfile which supports the building of the application package. The Final package that needs to be shipped will have an obfuscated Intellectual Property which is really hard to reverse Engineer.</p><h4>References</h4><ul><li><a href="https://www.techtarget.com/searchsecurity/definition/obfuscation">https://www.techtarget.com/searchsecurity/definition/obfuscation</a></li><li><a href="https://medium.com/@xpl/protecting-python-sources-using-cython-dcd940bb188e">https://medium.com/@xpl/protecting-python-sources-using-cython-dcd940bb188e</a></li><li><a href="https://gist.github.com/ctokheim/6c34dc1d672afca0676a">https://gist.github.com/ctokheim/6c34dc1d672afca0676a</a></li></ul><p>If you found this blog useful do leave a clap 👏 or comment 💬 . Any feedback or constructive criticism is welcomed 🙌.</p><p>You can reach out to me on <a href="https://in.linkedin.com/in/mohammed-vaghjipurwala-aab561b9">LinkedIn</a> or <a href="https://twitter.com/mohammedhv">Twitter</a> or in the comment section below.</p><blockquote>Happy Coding ..!!! <em>💻</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b97f88a460d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/python-source-code-obfuscation-6b97f88a460d">Python Source Code Obfuscation</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Boost up the performance of your Python code]]></title>
            <link>https://mohammedvaghjipurwala.medium.com/boost-up-the-performance-of-your-python-code-5e97e001d04b?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e97e001d04b</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[cython]]></category>
            <category><![CDATA[dataset]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Wed, 16 Sep 2020 02:16:01 GMT</pubDate>
            <atom:updated>2021-03-21T12:33:05.875Z</atom:updated>
            <content:encoded><![CDATA[<h4>Quick hack to improve the performance of the code with minimal changes</h4><p>Performance(Speed &amp; efficiency) is one of the key desires of every developer and an ask from the product. This small trick will help boost the performance of your code like magic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A0BPaFfN3eg6jbVnT9_uNg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@harleydavidson?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Harley-Davidson</a> on <a href="https://unsplash.com/s/photos/speed?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>A lot of people complain that Python is so slow and compare Python to C in the context of performance only, but they don’t compare in the context of fast development. Python development time is so fast because you don’t have to deal with pointers, memory management, etc.</p><p>This is one of the reasons Python is the most popular in most of the product based companies where in most cases, development time is more important than performance. Python has a great community and great libraries that work to achieve all the developer’s tasks. That being said, I will be talking about a package <strong><em>Cython </em></strong>in this article that will speed up your python code.<em> Let’s dive in…</em></p><p>To demonstrate these let us consider the pure Python example that generates a list of KMAX prime numbers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cde12b886a6f04d7bb41b14b33e79a1/href">https://medium.com/media/5cde12b886a6f04d7bb41b14b33e79a1/href</a></iframe><p>Timing our maxx_primes function, we see that this function takes on an average of about 98 milliseconds to run.</p><p>Now, Let’s make one simple change: We will load Cython, a module dedicated to bridging the gap between C and Python (more on this later).</p><h3>Cython: C-Extensions for Python</h3><p>Do you love easy syntax like Python and high performance like C? Cython is what you want. You can use Cython to write C extensions for Python. Your code will get translated into an optimized C code and will give you high performance.</p><h4>Install Cython</h4><p>To enable the C compiler, you need to install the Cython Library.</p><pre>pip install Cython</pre><p>To start the magic, we add <em>%%cython --annotate</em> at the top of the code which automatically converts Python code into C behind the scenes. The function maxx_primes execution will be done with C structures.</p><p>To enable support for Cython compilation, install Cython and load the Cython extension from within the Jupyter Notebook. To load the Cython extension add %load_ext cython in the top cell.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af0c95326b8acc70c51977c3985b0681/href">https://medium.com/media/af0c95326b8acc70c51977c3985b0681/href</a></iframe><p>Timing the code with this minor change, we see a time reduction to almost 35 milliseconds. That’s a pretty good discount (approx 64%) for doing such a small change!</p><blockquote>This increment in the performance may vary for different code functions</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*C0mwhbPsj21hrmZBxOUEwg.jpeg" /></figure><p>Cython’s --annotate option will help in Code analysis.</p><p>Adding the Cython extension just converts Python processes into C structures. We can still do better, <em>Lets add some optimization to our code</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ff7fbd8b43038d3f6347b79c8d38c3e/href">https://medium.com/media/0ff7fbd8b43038d3f6347b79c8d38c3e/href</a></iframe><p>Timing this new updated code, we see it took 2.21 ms approx. This is a <em>shocking</em> reduction in time to 95% approx compared to the raw code.</p><p><em>How did this happen ?!</em></p><p>we have added statically-typed C variables using the cdef keyword. Using these C variables results in faster execution of the code because the <em>variables</em> themselves have specified types, instead of figuring the type from the assigned value which is the feature in Python. For example, in Python one could set the same variable to an integer in one line and a string in another — a = “hello world” &amp; a = 1. In C, however, a statically-typed variable is set only to have one data type.</p><p>This inflexibility avoids the tremendous memory space overhead that is required by Python’s dynamic typing. Since a variable can take on so many possible values, more memory needs to be allocated. On the other hand, these limitations on the statically-typed variables assure that the memory space and execution process is much more efficient and this causes such a speedup in processing time.</p><h4>Static type declarations</h4><p>Static type declarations can be added to the Variables &amp; function which will give better performance. You can use all C types for declarations like int, float, double, etc.</p><p>cdef is the magic word that is used to declare C variables &amp; functions, either local or module-level.</p><h4>Variable Declaration in Cython</h4><pre><strong>cdef</strong> int i = 10</pre><h4>Function Declaration in Cython</h4><pre>def square(int i, char *s):<br>    ...</pre><pre>cdef int counter (unsigned long l, float f):<br>    ...</pre><p>cdef declared functions will not be visible to your Python code when you import the module. To make it visible you need to use cpdef instead<em>.</em></p><p>Voila… You made it!!!</p><h4>Cython advantages</h4><p>Besides being able to speed up your code, Cython grants several other advantages:</p><ul><li><strong>Working with external C libraries can be faster</strong></li></ul><p>Python packages like NumPy wrap C libraries in Python interfaces to make them easy to work with. However, going back and forth between Python and C through those wrappers can slow things down. Cython lets you talk to the underlying libraries directly, without Python in the way.</p><ul><li><strong>Cython can be used to obscure sensitive Python code</strong></li></ul><p>Python modules are trivially easy to decompile and inspect, but compiled binaries are not. When distributing a Python application to end-users, if you want to protect the modules from casual snooping, you can do so by compiling them with Cython and package the compiled binaries.</p><ul><li><strong>You can use both C and Python memory management</strong></li></ul><p>If you use Python objects, they’re memory-managed and garbage-collected the same as in regular Python. But if you want to create and manage your own C-level structures, and use malloc/free to work with them, you can do so.</p><ul><li><strong>Cython can use Python type hinting syntax</strong></li></ul><p>Python has a<em> type-hinting syntax </em>that is used mainly by linters and code checkers, rather than the CPython interpreter. Cython has its own custom syntax for code decorations, but with recent revisions of Cython, you can use Python type-hinting syntax to provide basic type hints to Cython as well.</p><h4>Conclusion</h4><p>There are many other methods to make Python code more efficient with Cython, the one demonstrated above is the easiest, least technical, and perhaps most high-return method. Note that examples are for illustration purposes; they can be optimized further.</p><h4>References</h4><ul><li><a href="https://nyu-cds.github.io/python-cython/01-syntax/">Cython Syntax</a></li><li><a href="https://levelup.gitconnected.com/this-one-trick-can-make-your-code-17-times-more-efficient-e65769006dfa">This One Trick Can Make Your Code 17 Times More Efficient</a></li></ul><blockquote>Happy Coding ..!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e97e001d04b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SafeGuard your WebApplication from cyber-attacks by Strengthening the WebServer]]></title>
            <link>https://mohammedvaghjipurwala.medium.com/safeguard-your-webapplication-from-cyber-attacks-by-strengthening-the-webserver-c8690357403f?source=rss-d359846ff688------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8690357403f</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[web-server]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[web-app-security]]></category>
            <dc:creator><![CDATA[Mohammed Vaghjipurwala]]></dc:creator>
            <pubDate>Sun, 10 May 2020 05:26:00 GMT</pubDate>
            <atom:updated>2020-09-02T14:40:21.373Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*OcXAl3wqV1P4oIfw.jpg" /></figure><p><em>WebServers play an extremely important role and all of us are aware of the critical impact they have on any Web project. In addition to safeguarding the application itself, it would be a good practice to think about securing every network component itself, which is associated with the development process. Web servers are the first line of defense for any Web Application, They form an integral part of project development and it is always a safe practice to strengthen those servers against being vulnerable to cyber-attacks.</em></p><h4>To safeguard your web application, The <a href="https://owasp.org/www-project-top-ten/">OWASP </a>Top 10 is a great starting point.</h4><p>The majority of these threats can be avoided by adding more security to the Webserver.</p><p>To demonstrate this, I have used NGINX WebServer with a sample HTML Page. At this point, there is no security added at the WebServer layer. As a result, the security report will give an F-grade.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EYi2s3Op-ApLZ36WIY7uFA.png" /><figcaption>Security Report before adding security</figcaption></figure><p>Below is the list of vulnerabilities found in the report</p><ul><li>SQL Injection</li><li>Missing Headers</li></ul><pre>- X-Frame-Options<br>- Strict-Transport-Security<br>- X-XSS-Protection<br>- X-Content-Type-Options<br>- Content-Security-Policy<br>- Referrer-Policy<br>- Feature-Policy<br>- X-Permitted-Cross-Domain-Policies</pre><ul><li>Nginx Version disclosure</li><li>Some SSL Related Vulnerabilities</li></ul><pre>- No SSL Certificates Installed<br>- Unsecure SSL Protocols Enabled<br>- Unsecure SSL Ciphers Enabled</pre><p>Added the below Nginx Headers to resolve the majority of the above-listed vulnerabilities.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97a0b561c44a62414682faeca7a62517/href">https://medium.com/media/97a0b561c44a62414682faeca7a62517/href</a></iframe><p>The same headers are available in tomcat as well. The Value of each header can be modified as per the web site requirements. Refer to the below URL for more details.</p><p><a href="https://geekflare.com/http-header-implementation/">How to Implement Security HTTP Headers to Prevent Vulnerabilities?</a></p><p>post implementing all the security headers on the WebServer, it scored an A-Grade from security perspective.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MkZqpg4-P2E8Uv9EekvCOg.png" /><figcaption>Security Report post implementing headers</figcaption></figure><h3>Bonus Tips for <strong>Secure Coding</strong></h3><ul><li><strong>Automate Security Functions</strong></li></ul><p>An automated check on the application at every development stage completion would help in a big way. The automation processes can be used to test the web application for its performance, Also can be tested for vulnerability against cyber-attacks<strong>.</strong></p><ul><li><strong>Generate a mock the security attack and test for stability</strong></li></ul><p>A good practice in an organization would be mocking the security attack and validating how the web application performs. This would help the developers to tackle this situation beforehand while coding.</p><ul><li><strong>Monitor All Traffic(Inbound &amp; Outbound)</strong></li></ul><p>Nowadays the data transmission over the network is humongous, hence its crucial to identify the suspicious traffic and block them immediately. This is best done by setting up firewalls and frequently testing the abilities of those firewalls as well as designing methods to improve their performance.</p><ul><li><strong>Encrypt all data</strong></li></ul><p>Web protocols are used while exchanging the data between the web client and the server. HTTPS, the most secure protocol should be used for encrypted data transmission.</p><ul><li><strong>Be updated about new types of vulnerabilities</strong></li></ul><p>Ignorance may be bliss, but it’s pretty risky in some situations. Hence, keeping yourself updated with the latest vulnerabilities and means to tackle them would be a good practice to protect your applications from attack or unanticipated failure.</p><ul><li><strong>Focus on Key Threats</strong></li></ul><p>Though keeping a track of the latest types of threats will surely help, it would be a good practice to focus more on the key threats that require continuous monitoring. Sometimes, the problems which we would have already heard about earlier and solved, could come up again and throw a different type of challenge as a Surprise!</p><ul><li><strong>Formulate a strategy and document your solutions</strong></li></ul><p>This is an extremely important practice. As a knowledge database, document your study of either a persisting problem or a new problem and your solution for that. The approaches used and the troubleshooting procedure could be very useful at critical junctures.</p><h3>References</h3><ul><li><a href="https://owasp.org/www-project-top-ten/">https://owasp.org/www-project-top-ten/</a></li><li><a href="https://securityheaders.com/">https://securityheaders.com/</a></li><li><a href="https://geekflare.com/http-header-implementation/">https://geekflare.com/http-header-implementation/</a></li></ul><blockquote>“It takes 20 years to build a reputation and a few minutes of cyber-incident to ruin it.” -Stephane Nappo</blockquote><blockquote>Happy Coding !!!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8690357403f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>