<?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 Marwa Ashraf on Medium]]></title>
        <description><![CDATA[Stories by Marwa Ashraf on Medium]]></description>
        <link>https://medium.com/@marwa1812?source=rss-324ce163ffa4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N4JUZZlrBCJMVF6tELEFww.jpeg</url>
            <title>Stories by Marwa Ashraf on Medium</title>
            <link>https://medium.com/@marwa1812?source=rss-324ce163ffa4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 02:45:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marwa1812/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[Security Mistakes Developers Make — Part 01]]></title>
            <link>https://medium.com/@marwa1812/security-mistakes-developers-make-part-01-063b8c53bd49?source=rss-324ce163ffa4------2</link>
            <guid isPermaLink="false">https://medium.com/p/063b8c53bd49</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[bola]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Marwa Ashraf]]></dc:creator>
            <pubDate>Fri, 23 Oct 2026 18:21:54 GMT</pubDate>
            <atom:updated>2026-10-23T18:21:54.727Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*NPS3Ko2UOQcKZO8g" /><figcaption>BOLA</figcaption></figure><h3>Your JWT Is Valid. Does That Mean the User Can Access the Resource?</h3><p>A protected API endpoint can authenticate every request correctly and still expose another user’s data.</p><p>Consider an e-commerce application where customers can retrieve their orders.</p><p>The developer implements JWT authentication and protects the endpoint:</p><pre>app.get(<br>  &quot;/api/orders/:orderId&quot;,<br>  authenticateToken,<br>  async (req, res) =&gt; {<br>    const order = await Order.findById(<br>      req.params.orderId<br>    );</pre><pre>    if (!order) {<br>      return res.sendStatus(404);<br>    }</pre><pre>    res.json(order);<br>  }<br>);</pre><p>The middleware verifies the user’s token. The database retrieves the requested order.</p><p>But there’s a missing security decision:</p><p><strong>Is this user actually allowed to access this particular order?</strong></p><h3>01. The vulnerability: Missing object-level authorization</h3><p>The endpoint trusts the requested orderId to identify the resource but doesn&#39;t verify whether the authenticated user has permission to access it.</p><p>An attacker with a valid account could send a request for an order belonging to another customer.</p><p>If the backend returns that order without checking authorization, sensitive information may be exposed.</p><p>This is an example of Broken Object Level Authorization (BOLA), also commonly associated with IDOR vulnerabilities.</p><p>OWASP identifies this as a major API security risk because endpoints frequently use client-supplied identifiers to retrieve and manipulate resources.</p><h3>02. The root cause: Trusting identity without enforcing permissions</h3><p>Let’s look at what the code actually guarantees.</p><p>authenticateToken establishes the authenticated user context, assuming the middleware correctly validates the token.</p><p>Order.findById(req.params.orderId) retrieves an order by its identifier.</p><p>Neither operation establishes that the user is authorized to access that order.</p><p>Authentication and authorization are separate security decisions. A valid token doesn’t automatically grant access to every resource.</p><p>The vulnerability exists because the application never connects the authenticated identity to the requested resource through an authorization policy.</p><h3>03. The attack scenario</h3><p>Assume Customer A has a valid JWT and can access their own order:</p><p>GET /api/orders/order_A</p><p>The application returns the order.</p><p>Customer A then changes the requested identifier:</p><p>GET /api/orders/order_B</p><p>If order_B belongs to Customer B and the backend returns it without an authorization check, Customer A has accessed another user&#39;s data.</p><p>The identifier doesn’t have to be sequential or predictable. Even UUIDs can be abused when an attacker obtains another resource’s identifier through logs, shared links, browser history, or other information sources.</p><p><strong>Making identifiers harder to guess is not a substitute for enforcing authorization.</strong></p><h3>04. The technical fix: Scope access to the authorization policy</h3><p>For an application where customers can only access their own orders, the query can enforce ownership directly:</p><pre>app.get(<br>  &quot;/api/orders/:orderId&quot;,<br>  authenticateToken,<br>  async (req, res) =&gt; {<br>    const order = await Order.findOne({<br>      _id: req.params.orderId,<br>      userId: req.user.id<br>    });</pre><pre>    if (!order) {<br>      return res.status(404).json({<br>        message: &quot;Order not found&quot;<br>      });<br>    }</pre><pre>    res.json(order);<br>  }<br>);</pre><p>The query now requires both the requested order ID and the authenticated user’s ID to match.</p><p>This reduces the risk of retrieving another customer’s order because the ownership constraint is part of the database query itself.</p><p>However, this implementation assumes that ownership is the complete access policy.</p><p>What if support agents can access customer orders? What if orders belong to organizations? What if a user can view an order but isn’t allowed to cancel it?</p><p>Those cases require explicit authorization rules that reflect the application’s actual business requirements.</p><p>A simple ownership check is not a universal authorization system.</p><h3>05. What about middleware?</h3><p>We could introduce a reusable middleware such as requireRole(&quot;admin&quot;) to protect administrative operations.</p><p>That’s useful for function-level permissions, but it doesn’t automatically solve object-level authorization.</p><p>A user might legitimately have permission to access an endpoint while lacking permission to access a particular record through it.</p><p>The important question is not just whether the user can call the endpoint. It’s whether the user can perform the requested action on the specific resource.</p><p>Authorization checks must be enforced on the server for every protected operation.</p><h3>06. How do you verify the fix?</h3><p>Don’t test only whether the endpoint works for a logged-in user.</p><p>Write integration tests that cover the authorization boundary:</p><ul><li><strong>Unauthenticated user:</strong> The request is rejected.</li><li><strong>Resource owner:</strong> The user can retrieve their own order.</li><li><strong>Different user:</strong> The user cannot retrieve another customer’s order.</li><li><strong>Modified identifier:</strong> Changing the order ID doesn’t bypass authorization.</li><li><strong>Unauthorized modification:</strong> A user cannot update or delete an order they aren’t permitted to manage.</li></ul><p>For the cross-user test, create two users and an order belonging to each. Authenticate as User A, request User B’s order, and assert that the response does not disclose the order’s contents.</p><p>Then repeat the test for operations that modify data.</p><p>This matters because a secure GET endpoint doesn&#39;t guarantee that the corresponding PATCH or DELETE endpoint enforces the same policy.</p><h3>07. The engineering takeaway</h3><p>When reviewing a protected API, don’t stop at checking whether authentication middleware is present.</p><p>Review how the application authorizes access to the requested resource and action.</p><p>Use explicit policies, enforce them consistently, and test both permitted and forbidden operations. In multi-tenant applications, include organization boundaries in those checks.</p><p>A valid JWT proves only what your authentication system establishes about the requester.</p><p><strong>It does not prove that the requester is entitled to the resource.</strong></p><h3>References</h3><ol><li>OWASP — <a href="https://owasp.org/www-project-api-security/">API1:2023 Broken Object Level Authorization</a></li><li>OWASP — <a href="https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html">Authorization Cheat Sheet</a></li><li>OWASP — <a href="https://top10.owasp.org/2025/A01_2025-Broken_Access_Control/">A01:2025 Broken Access Control</a></li></ol><p><strong>Next in the series:</strong> IDOR — Beyond Changing IDs: Finding and Preventing Object-Level Authorization Failures.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=063b8c53bd49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Not a Tester? Here’s How to Test Your Web Application as a Developer]]></title>
            <link>https://medium.com/@marwa1812/not-a-tester-heres-how-to-test-your-web-application-as-a-developer-3b8469d0087f?source=rss-324ce163ffa4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b8469d0087f</guid>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Marwa Ashraf]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 11:11:58 GMT</pubDate>
            <atom:updated>2026-10-22T11:11:58.145Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/673/0*ISGGq7Hm8Rxg54dE" /></figure><p>You built your application. The features work, the pages look good, and everything seems fine.</p><p>But is it really ready for users?</p><p>As developers, we often focus on writing code and implementing features. Sometimes, we test a feature once, see that it works, and move on to the next task.</p><p>But real users may do things we never expected. They might submit empty forms, click buttons twice, lose their internet connection, or try to access pages they are not allowed to see.</p><p>So, how can we make sure our applications work well without being professional testers?</p><p>Here are some practical tips that can help!</p><h3>1. Start by Testing Like a Real User</h3><p>Don’t test your application only from a developer’s point of view. Try to use it as if you were a real user.</p><p>For example, if you have a registration page, try to:</p><ul><li>Register with valid information.</li><li>Submit the form with empty fields.</li><li>Enter an invalid email address.</li><li>Use a password that doesn’t meet the requirements.</li><li>Click the submit button more than once.</li><li>Check what happens when the server returns an error.</li></ul><p>Ask yourself: What should happen? What could go wrong?</p><p><strong>Tip:</strong> Don’t test only when everything goes right. Try to find the situations where your application might fail.</p><h3>2. Check the UI and User Experience</h3><p>An application can work correctly and still provide a bad user experience.</p><p>Take some time to check how your application looks and feels.</p><p>Here are a few things to check:</p><ul><li>Do buttons and links work as expected?</li><li>Are error messages clear and helpful?</li><li>Does the layout work on mobile, tablet, and desktop?</li><li>Are there any broken images or unexpected empty spaces?</li><li>Do forms show validation messages correctly?</li><li>Are loading states and success messages displayed properly?</li><li>Can users navigate through the application easily?</li></ul><p>Don’t forget to test different screen sizes. A page that looks perfect on your laptop might be difficult to use on a mobile phone.</p><p><strong>Useful tool: Playwright</strong></p><p><a href="https://playwright.dev/">Playwright</a> allows you to automate browser actions and test complete user journeys, such as logging in, filling out forms, and navigating between pages.</p><p>You don’t have to automate everything. Start with the most important user journeys.</p><h3>3. Check What Happens When the API Fails</h3><p>Your frontend may work perfectly when the backend returns the expected response. But what happens when the API fails?</p><p>For example:</p><ul><li>What if the server returns a 500 Internal Server Error?</li><li>What if the request takes too long?</li><li>What if the response contains no data?</li><li>What if the user’s session expires?</li><li>What if the internet connection is lost?</li></ul><p>Your application should handle these situations gracefully.</p><p>Instead of showing a blank page or leaving the user confused, display a helpful message and provide a way to recover when possible.</p><p><strong>Useful tools:</strong></p><ul><li><strong>Browser DevTools:</strong> Check the Console and Network tabs to inspect errors, requests, and responses.</li><li><strong>Postman:</strong> Send requests to your APIs and check how they behave with different inputs and responses.</li><li><strong>Supertest:</strong> Test your Node.js and Express API endpoints automatically.</li></ul><p>You don’t need to guess what went wrong. Start by checking the evidence.</p><h3>4. Test the Important Business Logic</h3><p>Some bugs are more serious than a broken button or a layout issue.</p><p>Imagine your application handles payments, subscriptions, user roles, or limited quotas.</p><p>What happens if a user submits the same request twice? Can a normal user access an admin feature? Can a discount exceed the allowed limit?</p><p>These are examples of problems that deserve special attention.</p><p>Start by identifying the most important rules in your application, then test both valid and invalid cases.</p><p>For example, if your application has different user roles, verify that each role can access only the features it is allowed to use.</p><p>Remember that hiding a button in the frontend is not enough to protect an action. The backend must enforce the required permissions too.</p><p><strong>Useful tools:</strong></p><ul><li><strong>Jest or Vitest:</strong> Test business logic and individual functions.</li><li><strong>Supertest:</strong> Check API responses, validation, and access control.</li><li><strong>Postman:</strong> Manually test API endpoints with different requests and user credentials.</li></ul><h3>5. Don’t Forget Performance</h3><p>Your application might work correctly with one user but become slow when many users access it.</p><p>You don’t always need a complicated performance testing setup to start finding problems.</p><p>Begin with simple checks:</p><ul><li>Are pages taking too long to load?</li><li>Are API requests slower than expected?</li><li>Are images unnecessarily large?</li><li>Are you making repeated API calls?</li><li>Does the application remain responsive on mobile devices?</li></ul><p><strong>Useful tools:</strong></p><ul><li><strong>Lighthouse:</strong> Audits website performance, accessibility, SEO, and other aspects of page quality.</li><li><strong>Autocannon:</strong> Generates HTTP requests to help measure API performance under load.</li><li><strong>k6:</strong> Helps simulate user traffic and measure how an application performs under different load conditions.</li></ul><p>Start with Lighthouse and basic API measurements. Use load testing when you need to understand how your backend behaves under concurrent traffic.</p><h3>6. Check the Security Basics</h3><p>You don’t have to be a security expert to start checking some important things.</p><p>For example:</p><ul><li>Can someone access a protected page without logging in?</li><li>Can a user access another user’s private data?</li><li>Can a normal user perform an admin action?</li><li>Are sensitive details exposed in API responses?</li><li>Are your dependencies affected by known vulnerabilities?</li></ul><p><strong>Useful tools:</strong></p><ul><li><strong>OWASP ZAP:</strong> Helps identify common web application security vulnerabilities.</li><li><strong>npm audit:</strong> Checks your project’s dependencies for known security vulnerabilities.</li><li><strong>Browser DevTools and Postman:</strong> Help you inspect requests, responses, and authentication behavior.</li></ul><p>These tools can help you find potential problems, but passing a scan does not guarantee that your application is secure.</p><p>Always test permissions on the backend, not just in the user interface.</p><h3>7. Test Again After Making Changes</h3><p>You fixed a bug. Great!</p><p>But did the fix break something else?</p><p>For example, changing your authentication logic might affect login, registration, password reset, and protected pages.</p><p>This is why <strong>regression testing</strong> is important.</p><p>After making a change, test the affected feature and the related features that could be impacted.</p><p>Automated tests can make this process easier because you can run them again whenever your code changes.</p><p>If your project uses GitHub Actions or another CI/CD tool, you can also configure tests to run automatically before deployment.</p><h3>8. A Simple Testing Checklist to Get Started</h3><p>Before releasing a new feature or deploying your application, ask yourself:</p><p><strong>Functionality</strong></p><ul><li>Does the feature work as expected?</li><li>Have I tested valid and invalid inputs?</li><li>Have I checked the error cases?</li></ul><p><strong>UI and User Experience</strong></p><ul><li>Does the page look good on mobile and desktop?</li><li>Are loading, success, and error states handled?</li><li>Are buttons, links, and forms working correctly?</li></ul><p><strong>API and Backend</strong></p><ul><li>What happens when the API fails?</li><li>Are the responses and status codes correct?</li><li>Are authentication and permissions enforced?</li></ul><p><strong>Performance and Security</strong></p><ul><li>Are there any obvious performance problems?</li><li>Can users access data or actions they shouldn’t?</li><li>Have I checked for known dependency vulnerabilities?</li></ul><p><strong>Before Deployment</strong></p><ul><li>Have I tested the most important user journeys?</li><li>Have I rerun the relevant tests after my changes?</li><li>Have I checked the application in an environment close to production?</li></ul><p>You don’t have to do everything perfectly from day one. Start with the checks that matter most to your application and improve your testing process as you go.</p><h3>Final Thoughts</h3><p>As developers, we don’t need to become professional testers to take responsibility for the quality of our applications.</p><p>We just need to look beyond the code and think about the people who will use what we build.</p><p>Start small. Explore your application. Try unexpected inputs. Check the errors. Use tools that help you find problems before your users do.</p><p>And most importantly, don’t assume something works just because it worked once.</p><p><strong>Build it. Test it. Break it. Fix it. Make it better.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b8469d0087f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Actually Makes a System “Good”? Part 4: Strategies for Coping With Load]]></title>
            <link>https://medium.com/@marwa1812/what-actually-makes-a-system-good-part-4-strategies-for-coping-with-load-6d2200bde460?source=rss-324ce163ffa4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d2200bde460</guid>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Marwa Ashraf]]></dc:creator>
            <pubDate>Thu, 10 Sep 2026 20:41:00 GMT</pubDate>
            <atom:updated>2026-09-10T20:41:00.854Z</atom:updated>
            <content:encoded><![CDATA[<h3>There’s no universal scaling formula</h3><p>An architecture built to comfortably handle 10,000 requests per second will not simply keep working at 100,000 — it needs to change shape. There’s no generic “magic scaling” architecture that fits every workload. That said, there are a handful of recurring strategic choices worth understanding well.</p><h3>Scaling up vs. scaling out</h3><p><strong>Scaling up (vertical)</strong> means moving to a bigger machine — more CPU cores, more RAM, faster storage. It’s architecturally simple: no network consensus, no replication lag, no partitioning logic to reason about. The downside is cost and a hard ceiling — at some point you run out of bigger machines to buy, and the ones that exist get exponentially more expensive.</p><p><strong>Scaling out (horizontal)</strong> means spreading load across many smaller machines instead. It scales more predictably using ordinary hardware, but it costs you architectural simplicity — now you need load balancers, service discovery, and some way for nodes to agree on state.</p><p>In practice, a lot of production systems land somewhere pragmatic in the middle: a handful of solidly powerful servers is often easier and cheaper to run reliably than a sprawling fleet of tiny instances that constantly need coordinating.</p><h3>Elastic vs. manually managed scaling</h3><p><strong>Elastic systems</strong> automatically add or remove capacity based on live metrics — say, spinning up new instances once CPU usage crosses 70%. This is a good fit when traffic is genuinely unpredictable, though fast auto-scaling reactions can occasionally introduce their own surprises during a cascading incident.</p><p><strong>Manually scaled systems</strong> have capacity provisioned deliberately by a human, based on historical patterns. It’s less responsive to sudden spikes, but more predictable — and it avoids the scenario where an auto-scaler makes a bad situation worse by thrashing during an outage.</p><h3>Stateless vs. stateful is where the real difficulty lives</h3><p>Scaling stateless components — web servers, API layers, worker processes — is comparatively easy, because any instance can handle any incoming request without needing to coordinate with the others.</p><p>Stateful systems are a different story entirely. Moving a database or a message log from a single node to a distributed cluster introduces real complexity: consensus between nodes, the risk of a split-brain scenario, how to partition data sensibly, and trade-offs around consistency that don’t exist on a single machine.</p><p>A reasonable rule of thumb that holds up in a lot of real systems: keep your core transactional database on a single, vertically-scaled node for as long as that’s economically and technically workable, and only move to a distributed, sharded setup once your throughput or availability requirements genuinely force the issue.</p><h3>Wrapping up Scalability: Architectures fit workloads, not hype</h3><p>Looking at the scaling landscape as a whole: architectures are shaped entirely by their specific workload — a system built for a huge volume of tiny requests looks nothing like one built for a small number of massive ones, even if the total data moved is the same. Every scalable design is built on assumptions about which operations are common and which are rare, and if those assumptions drift over time, yesterday’s smart optimization quietly becomes today’s technical debt.</p><p>For a lot of early-stage products, the most pragmatic scaling decision is not to scale prematurely — the ability to iterate quickly and find product-market fit is usually worth far more than pre-building distributed infrastructure for a hypothetical future you haven’t earned yet. The real skill isn’t memorizing a list of “scalable patterns” — it’s understanding the general-purpose building blocks (caches, queues, replicas, partitions) well enough to combine them to match the actual shape of your load.</p><p><strong>Next up in this series:</strong> Now that we’ve tackled Reliability and Scalability, we hit the pillar where software engineering actually spends 80% of its budget: <strong>Part 5 — Maintainability.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d2200bde460" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Actually Makes a System “Good”? Part 3: Why Average Response Times Lie]]></title>
            <link>https://medium.com/@marwa1812/what-actually-makes-a-system-good-part-3-why-average-response-times-lie-ea75a66d8e4d?source=rss-324ce163ffa4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea75a66d8e4d</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Marwa Ashraf]]></dc:creator>
            <pubDate>Wed, 09 Sep 2026 18:56:00 GMT</pubDate>
            <atom:updated>2026-09-09T18:56:00.771Z</atom:updated>
            <content:encoded><![CDATA[<h3>Two different questions about performance</h3><p>Once you know your load parameters, the next step is figuring out how your system actually behaves as that load increases. In practice this comes down to one of two questions: if you hold resources constant and increase load, how much does performance degrade? Or, if you increase load, how much more hardware do you need to keep performance flat?</p><p>What you measure depends on the kind of system. For batch systems, the number that matters is throughput — how many records you can process per second, or how long a job over a fixed dataset takes. For online systems — APIs, web services — the number that matters is response time: how long a client waits between sending a request and getting the full answer back.</p><h3>Latency and response time aren’t the same thing</h3><p>These two words get used interchangeably, but they mean different things. Response time is the <em>total</em> time the client experiences — the actual work done on the server, plus network overhead, plus any time the request spent waiting in a queue before it was even picked up. Latency specifically refers to that waiting time — the period where a request is sitting idle, not yet being handled.</p><p>And here’s the part that surprises people the first time they measure it: if you send the exact same request to the exact same endpoint over and over, you won’t get the same response time twice. It forms a distribution, not a single number. That variation comes from things like OS-level context switching, network packet loss and retransmission, garbage collection pauses, page faults hitting disk instead of memory, and even minor physical factors in the hardware itself.</p><h3>Why the average is the wrong number to look at</h3><p>Say a service handles 100 requests. Ninety-nine of them come back in 10ms. One gets stuck on a slow I/O operation and takes 10 full seconds. Average that out and you get roughly 110ms — a number that describes literally none of your actual users. It hides the fact that 99% of people had a fast experience, and it completely buries the one person who waited ten agonizing seconds.</p><p>This is why performance engineering leans on <strong>percentiles</strong> instead. The median (p50) is the real midpoint — half your users were faster, half were slower — and it reflects what a “typical” request actually feels like. The higher percentiles (p95, p99, p99.9) tell you where the slow end of your distribution sits: if your p99 is 1.5 seconds, that means 1 in every 100 requests takes at least that long.</p><h3>Why the slow tail deserves so much attention</h3><p>It’s tempting to write off p99 as “just 1% of traffic, not worth optimizing for.” But there are two reasons that reasoning falls apart. First, in systems like e-commerce platforms, the users hitting your slowest response times are often disproportionately your highest-value customers — the ones with the biggest carts, the longest histories, the most data attached to their account. Second, the business impact of latency is measurable and significant: studies from large e-commerce companies have found that every extra 100ms of latency can cost around 1% of sales, and a full second of added delay can measurably drop customer satisfaction. This is also why real service-level agreements are written in percentiles, not averages — something like “healthy means p50 under 200ms and p99 under 1 second, over rolling 5-minute windows.”</p><h3>Two traps that make tail latency worse in distributed systems</h3><p><strong>Head-of-line blocking</strong>: a server can only run so many requests in parallel, limited by CPU cores and worker threads. If a handful of requests are slow, they occupy those slots, and fast requests behind them just sit waiting their turn — even a request that only needs 2ms of actual work can appear slow to the client purely because it queued behind something else.</p><p><strong>Tail latency amplification</strong>: this is the sneaky one in microservice architectures. A single user action often triggers many parallel backend calls, and the overall response can’t return until the <em>slowest</em> one finishes. Even if each individual service only has a small chance of hitting its own p99 outlier, once a request fans out into ten or twenty parallel internal calls, the odds that <em>at least one</em> of them hits a slow tail rise fast — meaning a much larger share of your overall traffic ends up experiencing worst-case latency than the per-service numbers would suggest.</p><p>One more practical note: you can’t average percentiles across servers — that’s not mathematically meaningful. To track percentiles over rolling time windows without keeping every raw data point in memory, systems typically use streaming approximation algorithms like t-digest or HdrHistogram.</p><p><em>Next in this series: Part 4 — the actual strategies for handling more load: scaling up vs. out, elastic vs. manual, and why stateful systems are the hard part.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea75a66d8e4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Actually Makes a System “Good”? Part 2: Scalability — Twitter’s Fan-Out Problem]]></title>
            <link>https://medium.com/@marwa1812/what-actually-makes-a-system-good-part-2-scalability-twitters-fan-out-problem-8abef8f213cd?source=rss-324ce163ffa4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8abef8f213cd</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Marwa Ashraf]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 18:51:01 GMT</pubDate>
            <atom:updated>2026-09-08T18:51:01.197Z</atom:updated>
            <content:encoded><![CDATA[<h3>Scalability isn’t a label</h3><p>It’s common to hear “this system scales” or “that one doesn’t” — but that framing doesn’t really mean anything on its own. The useful question is always conditional: <em>if load grows in a specific way, what are our options for handling it, and where do we need to add resources?</em></p><h3>You have to quantify load before you can talk about scaling it</h3><p>Before optimizing anything, you need a way to describe current load using concrete numbers — load parameters. Depending on the system, that might be requests per second, the ratio of reads to writes, the number of concurrent active connections, or your cache hit rate. And a general rule worth remembering: bottlenecks are almost never caused by the average case. They’re caused by outliers and skewed traffic patterns.</p><h3>The case study: Twitter’s fan-out problem</h3><p>Twitter’s two core operations, based on data the company published in 2012, illustrate this well:</p><ul><li><strong>Posting a tweet</strong>: roughly 4.6k requests/sec on average, peaking above 12k/sec</li><li><strong>Viewing a home timeline</strong>: roughly 300k requests/sec</li></ul><p>Handling 12,000 writes per second on its own isn’t hard for a modern system. The real bottleneck was <strong>fan-out</strong>: each user follows a lot of people, and each user is followed by a lot of people. Twitter went through roughly three structural approaches to deal with it.</p><h3>Approach 1: compute the timeline at read time</h3><p>A new tweet is just inserted into one global table. When a user opens their timeline, the system runs a join across the tables — tweets, users, and who-follows-whom — pulls the recent tweets from everyone they follow, and sorts them by time. It’s a simple, standard relational query.</p><p>The problem: at 300,000 reads per second, running that join and sort on every single request puts enormous strain on the database’s CPU and memory. The read path becomes the bottleneck.</p><h3>Approach 2: pre-compute the timeline at write time</h3><p>Instead, give every user their own timeline cache — essentially a personal mailbox. When someone posts, the system looks up all of their followers and pushes the new tweet directly into each follower’s cache. Reading a timeline becomes an almost instant lookup, because the work was already done ahead of time.</p><p>This works well for a typical user with, say, a few dozen or a few hundred followers — a single tweet turns into a manageable number of cache writes. It falls apart for the outliers: an account with tens of millions of followers turns a single tweet into tens of millions of near-simultaneous cache writes, backing up queues and slowing down the entire pipeline for everyone.</p><h3>Approach 3: a hybrid — because not all accounts are the same</h3><p>The actual production answer was to stop treating every account the same way:</p><ul><li><strong>Regular accounts</strong> (below some follower-count threshold) use fan-out on write — their tweets get pushed directly into followers’ caches as before.</li><li><strong>High-follower accounts</strong> are exempted from fan-out on write. Their tweets just get stored once, in their own timeline.</li><li>When a user opens their feed, the system merges their pre-computed cache with a small number of on-demand lookups for the few high-follower accounts they follow, and sorts the combined result in memory.</li></ul><p>This gets the cheap-read benefit for the vast majority of accounts, while avoiding the write explosion that high-follower accounts would otherwise cause.</p><h3>The takeaways that generalize beyond Twitter</h3><p>A few principles come out of this case that apply to almost any system with a similar read/write imbalance:</p><ul><li><strong>Load parameters shape the architecture.</strong> There’s no universal answer — you need to know whether your system is read-heavy, write-heavy, or dominated by a small number of extreme outliers before picking an approach.</li><li><strong>Fan-out on write vs. fan-out on read is really a choice of where you pay the cost</strong> — during ingestion (when data is written) or during presentation (when data is read). Neither is “correct” in the abstract.</li><li><strong>Averages are misleading, and outliers are where systems actually break.</strong> A design built around the “typical” case will often fail exactly where it matters most — the accounts, requests, or users at the extreme end of the distribution.</li></ul><p><em>Next in this series: Part 3 — why average response times lie to you, and what percentiles actually tell you instead.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8abef8f213cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Actually Makes a System “Good”? Part 1: Reliability]]></title>
            <link>https://medium.com/@marwa1812/what-actually-makes-a-system-good-part-1-reliability-259e90d14e5d?source=rss-324ce163ffa4------2</link>
            <guid isPermaLink="false">https://medium.com/p/259e90d14e5d</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[reliability]]></category>
            <dc:creator><![CDATA[Marwa Ashraf]]></dc:creator>
            <pubDate>Mon, 07 Sep 2026 17:49:50 GMT</pubDate>
            <atom:updated>2026-09-07T17:49:50.484Z</atom:updated>
            <content:encoded><![CDATA[<h3>Series intro</h3><p>Most engineering advice focuses on code quality — clean architecture, design patterns, readable functions. But when systems actually break in production, it’s rarely the code structure that’s the problem. It’s how data moves, where state lives, and how the system behaves under pressure.</p><p>This is the first in a short series based on the three pillars that Chapter 1 of <em>Designing Data-Intensive Applications</em> uses to frame good system design: <strong>Reliability, Scalability, and Maintainability</strong>. This part is about Reliability.</p><h3>Systems are compositions, not single databases</h3><p>In production, a “data system” is almost never one database. It’s usually several specialized tools wired together — a primary database as the source of truth, a cache in front of it to cut down on read latency, a search index for anything text-heavy, and a message queue to handle background work asynchronously.</p><p>The moment you combine tools like this, your application code takes on a new job: keeping them in sync. If the primary database changes, someone has to invalidate the cache and update the search index. That’s not really “application development” anymore — it’s data system design, and it comes with a new set of hard questions: how do you keep things consistent when one of these pieces fails intermittently? How do you keep performance acceptable when part of the system is degraded? How do you scale predictably as load grows?</p><h3>Reliability, defined</h3><p>Reliability, in plain terms, means <strong>continuing to work correctly even when something goes wrong</strong>. “Working correctly” usually breaks down into a few expectations: the system does what the user expects, it tolerates bad input and unexpected usage without falling over, performance holds up under normal load, and it keeps unauthorized access out.</p><h3>Fault vs. failure — the distinction that actually matters</h3><p>This is the one concept worth internalizing above everything else in this chapter: a <strong>fault</strong> is a single component behaving outside its spec — a disk dying, one server crashing, a network switch dropping packets. A <strong>failure</strong> is the system as a whole no longer serving the user — the checkout API returning a 500 to every customer.</p><p>A system is “fault-tolerant” when it has mechanisms that stop individual faults from escalating into a full failure. And it’s worth saying plainly: zero faults is not a realistic goal. No architecture survives every conceivable disaster. The real engineering question is which realistic categories of fault you’re designing defenses against.</p><p>One counterintuitive idea worth knowing: some of the most reliable systems <em>deliberately</em> inject faults into production on purpose. Netflix’s Chaos Monkey randomly kills live instances — not to cause chaos for its own sake, but because exercising your failure paths constantly is the only way to be confident they’ll actually work when a real incident happens. The general principle is: tolerating faults is usually better than trying to prevent them outright — except in security, where a breach can’t be undone, so prevention has to come first there.</p><h3>The three categories of faults</h3><p><strong>Hardware faults</strong> tend to be random and uncorrelated — one disk failing doesn’t make its neighbor more likely to fail (barring a shared cause, like a cooling failure in the whole rack). The scale of this matters more than it sounds: enterprise drives have a mean time to failure of roughly 10 to 50 years, but in a cluster of 10,000 disks, that statistically works out to about one disk dying <em>every day</em>. The classic defense is redundancy — RAID, dual power supplies, backup generators. But modern cloud platforms shifted the model: VMs can disappear without warning, so the newer approach is designing software that tolerates losing an entire node, which has a nice side effect — you can patch or upgrade machines one at a time with zero downtime.</p><p><strong>Software errors</strong> are the more dangerous category precisely because they’re systematic, not random. Since every instance runs the same code, a bug can take out an entire fleet at once — the 2012 Linux kernel leap-second bug is a well-known real example, where a timing edge case caused servers around the world to hang simultaneously. Other common shapes: a runaway process quietly eating shared memory or CPU, or a small slowdown in one service cascading into a domino effect across dependent services. There’s no single fix — process isolation, testing edge cases deliberately, and letting processes crash-and-restart cleanly all help.</p><p><strong>Human errors</strong> are the uncomfortable one. Large-scale studies consistently find that operator configuration mistakes cause more outages than hardware failure does — hardware is typically responsible for only 10–25% of incidents. Designing around this means making the right action easy and the destructive action hard, giving engineers a sandboxed environment with realistic (sanitized) data to experiment safely, testing edge cases automatically, and making recovery fast — quick rollbacks, canary releases that expose new code to a small percentage of users first, and tooling to recompute data if something was corrupted.</p><h3>Why this matters even outside “critical” systems</h3><p>Reliability isn’t just a concern for spacecraft or power grids. For an e-commerce business, downtime is direct lost revenue and possible SLA penalties. For a consumer app, losing someone’s data — their photos, their history — permanently damages trust in a way that’s hard to earn back.</p><p>That doesn’t mean reliability is always worth maximizing. Cutting corners can be a legitimate, conscious trade-off — for an early prototype still validating product-market fit, or a business with margins too thin to justify the operational cost of full redundancy. The key word is <em>conscious</em>: know when you’re making that trade, rather than discovering it during an outage.</p><p><em>Next in this series: Part 2 — how Twitter’s fan-out problem shows scalability is never a yes/no label, it’s a set of trade-offs.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=259e90d14e5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reliability in code — my quick reference]]></title>
            <link>https://medium.com/@marwa1812/reliability-in-code-my-quick-reference-dc6aa8678401?source=rss-324ce163ffa4------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc6aa8678401</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[reliability]]></category>
            <category><![CDATA[systems-thinking]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Marwa Ashraf]]></dc:creator>
            <pubDate>Sun, 06 Sep 2026 15:02:28 GMT</pubDate>
            <atom:updated>2026-09-06T15:02:28.881Z</atom:updated>
            <content:encoded><![CDATA[<p>Reliability sounds like a big fancy word, but it really just means one thing: a small problem shouldn’t turn into a big one. Here’s how I actually apply that in code, not just in theory.</p><h3>1. Never trust the client to tell you who they are</h3><p>If identity comes from the request body instead of a verified session, you’re exposing yourself to what’s known as <strong>BOLA / IDOR</strong> (Broken Object Level Authorization / Insecure Direct Object Reference) — basically, anyone can pretend to be anyone else just by changing an id in the payload.</p><pre>// bad — client controls the identity<br>app.post(&#39;/api/proposals&#39;, async (req, res) =&gt; {<br>  const { entrepreneur_id, offer_amount } = req.body;<br>  const proposal = await Proposal.create({ entrepreneur_id, offer_amount });<br>  res.status(201).json(proposal);<br>});</pre><pre>// good — identity comes strictly from the verified token/session<br>app.post(&#39;/api/proposals&#39;, authMiddleware, async (req, res) =&gt; {<br>  const proposal = await Proposal.create({<br>    entrepreneur_id: req.user.id,<br>    offer_amount: req.body.offer_amount,<br>  });<br>  res.status(201).json(proposal);<br>});</pre><h3>2. Validate the shape, and strip anything you didn’t ask for</h3><p>Checking types isn’t enough on its own — you also want to drop any extra fields the client snuck into the payload, otherwise you’re open to mass-assignment issues (someone adding a field like role: &quot;admin&quot; that you never intended to accept).</p><pre>const proposalSchema = Joi.object({<br>  offer_amount: Joi.number().positive().precision(2).required(),<br>  message: Joi.string().trim().max(500).optional(),<br>});</pre><pre>app.post(&#39;/api/proposals&#39;, authMiddleware, async (req, res) =&gt; {<br>  const { error, value } = proposalSchema.validate(req.body, {<br>    abortEarly: false,<br>    stripUnknown: true, // drop anything not in the schema<br>  });</pre><pre>  if (error) {<br>    return res.status(400).json({<br>      error: &#39;ValidationFailed&#39;,<br>      details: error.details.map((d) =&gt; d.message),<br>    });<br>  }</pre><pre>  const proposal = await Proposal.create({ entrepreneur_id: req.user.id, ...value });<br>  res.status(201).json(proposal);<br>});</pre><h3>3. Only retry the failures worth retrying, and add jitter</h3><p>Not every failure deserves a retry. A 400 or 404 will fail again no matter how many times you try — retrying those just wastes time. Retry only network drops, 429, and 5xx. And instead of every failed request waking up at the exact same moment (which can hammer a recovering service all at once — the &quot;thundering herd&quot; problem), add some randomness to the wait time.</p><pre>async function fetchWithRetry(url, options = {}, maxRetries = 3) {<br>  for (let attempt = 1; attempt &lt;= maxRetries; attempt++) {<br>    try {<br>      const response = await fetch(url, options);<br>      if (response.ok) return await response.json();</pre><pre>      const isTransient = response.status === 429 || response.status &gt;= 500;<br>      if (!isTransient || attempt === maxRetries) {<br>        throw new Error(`HTTP_${response.status}`);<br>      }<br>    } catch (err) {<br>      if (attempt === maxRetries || err.message?.startsWith(&#39;HTTP_4&#39;)) throw err;<br>    }</pre><pre>    // exponential backoff, but randomized so retries don&#39;t all land together<br>    const baseBackoff = 2 ** attempt * 100;<br>    const jitteredDelay = Math.floor(Math.random() * baseBackoff);<br>    await new Promise((r) =&gt; setTimeout(r, jitteredDelay));<br>  }<br>}</pre><h3>4. Have a fallback — but don’t hide that it happened</h3><pre>async function getUserAvatar(userId) {<br>  try {<br>    return (await cloudStorage.getFile(`avatars/${userId}`)).url;<br>  } catch (err) {<br>    // still track it — a fallback that happens constantly is a problem you want to know about<br>    metrics.increment(&#39;avatar.fallback_used&#39;, { reason: err.code || &#39;storage_error&#39; });<br>    logger.warn(&#39;Avatar fetch failed, serving fallback&#39;, { userId, error: err.message });<br>    return &#39;/assets/default-avatar.png&#39;;<br>  }<br>}</pre><h3>5. Rate limit — and remember in-memory limits don’t survive scaling</h3><p>A rate limiter that just counts requests in memory works fine on one server. The moment you run more than one instance (multiple containers, pods, whatever), each instance counts separately, so the real limit quietly becomes “5 times whatever number of instances you’re running.” The fix is to store the counts somewhere shared, like Redis.</p><pre>const authLimiter = rateLimit({<br>  windowMs: 15 * 60 * 1000,<br>  max: 5,<br>  standardHeaders: true,<br>  legacyHeaders: false,<br>  store: new RedisStore({<br>    sendCommand: (...args) =&gt; redisClient.sendCommand(args),<br>  }),<br>  message: { error: &#39;Too many login attempts. Try again in 15 minutes.&#39; },<br>});</pre><pre>app.post(&#39;/api/auth/login&#39;, authLimiter, loginController);</pre><h3>6. Log in a shape you can actually search later</h3><p>A plain string in console.log is fine while you&#39;re staring at your terminal, but it&#39;s useless once you have real traffic and need to search across thousands of logs for one failing request. Structured (JSON) logs with an id that ties the whole request together (traceId) make that possible.</p><pre>// not searchable later<br>console.log(`Payment failed for order ${order.id}`);</pre><pre>// searchable, and traceable across the whole request<br>logger.error(&#39;Payment processing failed&#39;, {<br>  event: &#39;PAYMENT_WEBHOOK_FAILURE&#39;,<br>  traceId: req.headers[&#39;x-trace-id&#39;] || &#39;local-trace&#39;,<br>  orderId: order.id,<br>  userId: req.user?.id,<br>  gatewayErrorCode: err.code,<br>  timestamp: new Date().toISOString(),<br>});</pre><h3>7. Test the invariant, not just the happy path</h3><p>A unit test tells you the function works. An integration test tells you the actual security boundary holds — e.g. that even if someone tries to sneak in a fake id, the database still ends up with the real one.</p><pre>it(&#39;should ignore body-provided identity and persist the authenticated user&#39;, async () =&gt; {<br>  const validToken = generateAuthToken({ id: &#39;real-user-123&#39; });</pre><pre>  const response = await request(app)<br>    .post(&#39;/api/proposals&#39;)<br>    .set(&#39;Authorization&#39;, `Bearer ${validToken}`)<br>    .send({ entrepreneur_id: &#39;spoofed-attacker-id&#39;, offer_amount: 5000 });</pre><pre>  const stored = await Proposal.findById(response.body.id);<br>  expect(stored.entrepreneur_id).toBe(&#39;real-user-123&#39;);<br>  expect(stored.entrepreneur_id).not.toBe(&#39;spoofed-attacker-id&#39;);<br>});</pre><h3>Quick lookup table</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*Cnua9cw4BPf5P9xoWThHUw.png" /><figcaption>Pragmatic Engineering</figcaption></figure><p><strong>One rule to keep in mind:</strong> start with identity checks, input validation, and structured logs — those matter from day one. Add distributed rate limiting, retry/jitter, and fallbacks once you actually have the scale or the external dependency that needs them. Adding them earlier than that is just extra code to maintain for a problem you don’t have yet.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc6aa8678401" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>