<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Surhid Amatya</title>
    <description>The latest articles on DEV Community by Surhid Amatya (@surhidamatya).</description>
    <link>https://dev.to/surhidamatya</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F379207%2Fcfe00353-72cc-4d52-acb0-59b524814aa6.png</url>
      <title>DEV Community: Surhid Amatya</title>
      <link>https://dev.to/surhidamatya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/surhidamatya"/>
    <language>en</language>
    <item>
      <title>Notification Service, Part 9: Architecture Technical Breakdown</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Tue, 24 Nov 2026 03:54:12 +0000</pubDate>
      <link>https://dev.to/surhidamatya/notification-service-part-9-architecture-technical-breakdown-2lil</link>
      <guid>https://dev.to/surhidamatya/notification-service-part-9-architecture-technical-breakdown-2lil</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb8zeadostjc6d43kc8pq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb8zeadostjc6d43kc8pq.png" alt=" " width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/surhidamatya/from-memory-to-machines-how-notifications-actually-work-1f75"&gt;previous blog&lt;/a&gt; we looked at notifications through a diagram. This post goes through every box in it and what it does in a real implementation. It's the reference design: the full picture of a centralized, event-driven notification system that delivers to iOS, Android and email, with authentication, rate limiting, personalization, retries and analytics.&lt;/p&gt;

&lt;p&gt;The core system emits events. A dedicated notification service decides if, when, how and through which channel a notification gets delivered.&lt;/p&gt;

&lt;p&gt;The numbers in the headings match the figure (Fig 1.1, 1.2 and so on). The last section compares the design with the service the other posts in this series describe, because a few pieces of the diagram aren't built there yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Event producers (Service N), Fig 1.1
&lt;/h2&gt;

&lt;p&gt;Service N stands for any upstream service in the ecosystem. Some examples:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Order service&lt;/li&gt;
&lt;li&gt;Payment service&lt;/li&gt;
&lt;li&gt;Cart service&lt;/li&gt;
&lt;li&gt;User service&lt;/li&gt;
&lt;li&gt;Marketing automation service&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These services never send notifications themselves. They emit a structured event instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;eventType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ORDER_PLACED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That keeps business logic and notification delivery apart.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Notification servers (API layer), Fig 1.2
&lt;/h2&gt;

&lt;p&gt;The notification servers are the entry point. Their job is to keep the system safe before any notification logic runs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Authentication: check that the request or event comes from a trusted service, so nobody can trigger notifications without permission.&lt;/li&gt;
&lt;li&gt;Rate limiting: protect downstream systems from overload, enforce per-user or per-service limits and stop spam.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  3. Cache and database, Fig 1.10 and 1.8
&lt;/h2&gt;

&lt;p&gt;The notification server pulls the data it needs from a cache first. The cache holds user preferences, device tokens and counts of recently sent notifications, so lookups stay fast.&lt;/p&gt;

&lt;p&gt;The database stores user notification settings, device information (iOS token, Android token, email address) and channel preferences (push, email, SMS). The cache is there for latency. The database is the source of truth.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Notification decision logic
&lt;/h2&gt;

&lt;p&gt;With the request validated and the data loaded, the system decides:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is the user eligible for a notification?&lt;/li&gt;
&lt;li&gt;Which channel should be used?&lt;/li&gt;
&lt;li&gt;Should it be sent now or deferred?&lt;/li&gt;
&lt;li&gt;Is it suppressed by a rate limit?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Only eligible notifications go any further.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Notification templates, Fig 1.6
&lt;/h2&gt;

&lt;p&gt;Templates define the shape of a message, not how it's delivered. They hold the static layout, placeholders for dynamic data and any channel-specific formatting (a push body is not an email body). For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="n"&gt;Title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Order Update"&lt;/span&gt;
&lt;span class="n"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Hi {{name}}, your order {{orderId}} has been shipped."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Templates keep messages consistent, make localization possible and keep content out of the logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Workers (asynchronous processing), Fig 1.3
&lt;/h2&gt;

&lt;p&gt;Workers do the actual delivery, not the API servers. That gives you non-blocking request handling, retry support and horizontal scaling. A worker pulls prepared notification jobs, calls the external provider (APNS, FCM, SMTP), retries on transient failures and records success or failure. A failure here stays isolated from the upstream services.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Platform gateways, Fig 1.4
&lt;/h2&gt;

&lt;p&gt;The diagram shows APNS explicitly, for iOS. There are equivalents for Android (FCM), email (SMTP) and SMS (provider APIs). The notification system never talks to a device directly. It always goes through an official platform gateway.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Device delivery, Fig 1.5
&lt;/h2&gt;

&lt;p&gt;For iOS, APNS delivers the notification to the device using its device token. At that point the notification is shown, and the user may open or click it. The figure only shows APNS, but Android uses FCM and email uses SMTP in the same position.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Notification logs, Fig 1.7
&lt;/h2&gt;

&lt;p&gt;Every notification attempt is logged: notification ID, user ID, channel, timestamp and delivery status. Those logs matter for auditing, debugging, compliance and customer support. They also let the product team see whether notifications actually reached devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Analytics service, Fig 1.9
&lt;/h2&gt;

&lt;p&gt;Analytics runs in parallel with delivery. It tracks pending notifications, successful sends, delivery failures and clicks from the device. Click tracking closes the loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Notification sent → User action → Analytics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That data feeds campaign performance, personalization and later targeting decisions. Mostly it tells the product team how people engage with notifications, which helps them decide what to try next.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Retry and failure handling, Fig 1.12
&lt;/h2&gt;

&lt;p&gt;When a delivery attempt fails, the worker retries according to a retry policy, the error goes to analytics and the failure doesn't block the rest of the system. Retries raise the chance that a notification reaches the user at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  How this maps to the real service
&lt;/h2&gt;

&lt;p&gt;Parts 3 to 8 of this series describe a service built from this design. A few pieces differ, and it's better to say so plainly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Producers and intake (1, 2):&lt;/strong&gt; Other services publish events to Kafka, one topic and one listener per event type (Part 3). There's no rate limiter at intake. Load is contained by capped concurrency and circuit breakers (Part 7). A separate REST API serves the timeline, preferences and template management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache, database and decision logic (3, 4):&lt;/strong&gt; The in-app timeline and its unread counters live in DynamoDB (Part 4). Delivery details such as device tokens and email addresses travel inside the event, so nothing is looked up at send time. Today the event itself decides which channels are used. User preferences aren't checked before sending (Part 3).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Templates (5):&lt;/strong&gt; Email templates live in Brevo, and the service only maps an email type to a template ID, so a redesigned template goes live without a deployment (Part 6).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Workers (6):&lt;/strong&gt; There's no separate worker fleet. The Kafka listeners are the workers, with capped async executors for work off the main path (Parts 3 and 7).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gateways and delivery (7, 8):&lt;/strong&gt; Push goes through Firebase Cloud Messaging for both iOS and Android (Part 5). Email goes through the Brevo API and SMS through Twilio (Part 6).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logs (9):&lt;/strong&gt; Each stored notification carries a delivery status of pending, sent, failed or skipped, plus a delivery metric per channel (Part 8).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analytics (10):&lt;/strong&gt; Not in this service. There's no click or open tracking, and measuring engagement would need the client apps to report events (Part 8).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retries (11):&lt;/strong&gt; The design calls for them, but the service doesn't retry failed sends automatically yet. External channels are at-least-once, so adding retries needs the same care about duplicates (Parts 4 and 7).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the diagram is the destination, and the other posts show how far the real service has got.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Notification Service, Part 8: Delivery Status and Observability</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Tue, 24 Nov 2026 03:51:00 +0000</pubDate>
      <link>https://dev.to/surhidamatya/notification-service-part-8-delivery-status-and-observability-njh</link>
      <guid>https://dev.to/surhidamatya/notification-service-part-8-delivery-status-and-observability-njh</guid>
      <description>&lt;p&gt;A notification service only helps if you can tell whether it's working. Support needs to answer "did this user get the message?", and engineers want to see failures before customers report them. This last post covers what the service records and exposes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delivery status per notification
&lt;/h2&gt;

&lt;p&gt;Every stored in-app notification has a delivery status that follows the push attempt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;PENDING&lt;/code&gt;: stored, dispatch not finished yet.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SENT&lt;/code&gt;: the push call to Firebase completed.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;FAILED&lt;/code&gt;: the push call failed, or the circuit breaker was open.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SKIPPED&lt;/code&gt;: nothing to send, for example because the event had no device tokens.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two limits are worth knowing. &lt;code&gt;SENT&lt;/code&gt; means the provider accepted the message. It doesn't mean the device showed it. And the status tracks the push attempt, since the in-app record is what gets stored.&lt;/p&gt;

&lt;p&gt;The status update runs asynchronously, so recording it never holds up the next event.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read state
&lt;/h2&gt;

&lt;p&gt;Separately from delivery, each notification is either &lt;code&gt;UNREAD&lt;/code&gt; or &lt;code&gt;READ&lt;/code&gt;. The unread count lives on a per-user summary item, so the badge number is one lookup (Part 4).&lt;/p&gt;

&lt;h2&gt;
  
  
  Metrics
&lt;/h2&gt;

&lt;p&gt;The service counts deliveries with a single Micrometer metric, &lt;code&gt;notification.delivery&lt;/code&gt;, which has two tags: channel (email, sms, push or in-app) and outcome (success or failure).&lt;/p&gt;

&lt;p&gt;Tag values come from a small fixed set. They never contain user IDs, phone numbers or email addresses, which keeps cardinality low and keeps personal data out of monitoring.&lt;/p&gt;

&lt;p&gt;Push is counted per device token, not per call. A multicast to 3 devices where 1 fails records 2 successes and 1 failure, which gives a more honest delivery rate.&lt;/p&gt;

&lt;p&gt;The counters are exposed through Actuator in Prometheus format. Only the health, info, metrics and Prometheus endpoints are exposed. Environment, bean and heap-dump endpoints stay off.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you can answer with this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Is a channel degrading? Watch the failure share per channel. A rising push failure rate next to an open circuit breaker points at Firebase.&lt;/li&gt;
&lt;li&gt;Is a user missing messages? Look at that user's timeline and delivery statuses.&lt;/li&gt;
&lt;li&gt;Are duplicates arriving? The idempotency check logs every duplicate event it rejects.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What isn't there
&lt;/h2&gt;

&lt;p&gt;There's no click or open tracking, and no analytics pipeline, in this service. Delivery status says a message was handed to a provider, not that anyone did anything with it. Measuring engagement would need the client apps to report events, and that's a separate piece of work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up the series
&lt;/h2&gt;

&lt;p&gt;Events come in through Kafka, one listener per type. The in-app timeline is stored idempotently in DynamoDB. Push, email and SMS go out through guarded provider clients. Bounded concurrency and circuit breakers contain failures, and statuses and metrics show what happened.&lt;/p&gt;

&lt;p&gt;The gaps are known ones: no automatic retries for external sends, external channels are at-least-once, and there's no engagement analytics. Each has an obvious place to be added.&lt;/p&gt;

</description>
      <category>observability</category>
      <category>monitoring</category>
      <category>backend</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Notification Service, Part 7: Concurrency and Resilience</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Tue, 24 Nov 2026 03:50:42 +0000</pubDate>
      <link>https://dev.to/surhidamatya/notification-service-part-7-concurrency-and-resilience-5c28</link>
      <guid>https://dev.to/surhidamatya/notification-service-part-7-concurrency-and-resilience-5c28</guid>
      <description>&lt;p&gt;A notification service spends most of its time waiting on someone else: Firebase, Brevo, Twilio, DynamoDB, Kafka. Heavy computation isn't the risk. The risk is a slow or failing provider letting work pile up. This post covers what the service uses to stay stable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who does the work
&lt;/h2&gt;

&lt;p&gt;There's no separate job queue or worker fleet. The Kafka listeners are the workers: each one consumes an event, stores it and calls the providers. Kafka is the queue, and adding consumer replicas is how you add capacity (Part 3).&lt;/p&gt;

&lt;p&gt;The REST API is a different thing. It serves the timeline, preferences and template management, and it doesn't send event notifications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Virtual threads
&lt;/h2&gt;

&lt;p&gt;The service runs on virtual threads, for web requests and for async tasks. They're cheap, so a call waiting on a slow provider doesn't hold an operating-system thread. A thread per task is affordable again, and the code can stay simple and blocking in style.&lt;/p&gt;

&lt;h2&gt;
  
  
  Capped async executors
&lt;/h2&gt;

&lt;p&gt;Some work runs off the main listener path, like delivery status updates and publishing Kafka events. It runs on async executors that create one virtual thread per task, with a semaphore capping how many tasks are in flight:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The notification executor allows 50 concurrent tasks and handles delivery status updates.&lt;/li&gt;
&lt;li&gt;The general executor allows 100 and handles other async work, such as publishing events.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a cap is reached, new tasks wait for a free slot. Without the cap, a provider slowdown would let outbound work grow without limit against connection pools that are finite. The caps are configuration values, so they can be tuned per environment.&lt;/p&gt;

&lt;p&gt;The executors also carry the security context over to the new thread, so work started on behalf of a user keeps that user's identity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Circuit breakers
&lt;/h2&gt;

&lt;p&gt;SMS and push each have a circuit breaker, and both use the same settings. The breaker looks at the last 20 calls and needs at least 10 before it judges. It opens if 50% or more fail, or if 80% or more are slower than 5 seconds. Once open, calls fail instantly for 30 seconds. Then it lets 5 test calls through and closes again if they succeed.&lt;/p&gt;

&lt;p&gt;The slow-call rule works like a soft timeout. A provider that answers, but slowly, gets treated as failing before it can use up the pool.&lt;/p&gt;

&lt;p&gt;Two details matter in practice. The breaker wraps only the provider call, so unrelated failures don't count against it. And an open breaker doesn't turn the service's health check unhealthy, so a provider outage doesn't cause restarts that wouldn't fix anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure isolation
&lt;/h2&gt;

&lt;p&gt;Provider errors are caught where they happen. A push failure becomes a &lt;code&gt;FAILED&lt;/code&gt; status and a metric, not an exception that kills the listener. One failing channel doesn't stop the others, and one bad event doesn't block the partition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retries
&lt;/h2&gt;

&lt;p&gt;The service has no custom retry or backoff for push, email or SMS. A failed send is recorded and left alone. A database write that throws goes back to Kafka's standard consumer error handling, and the idempotent store (Part 4) makes a redelivery safe.&lt;/p&gt;

&lt;p&gt;Retries for transient provider failures are the obvious next improvement. They'd need care about duplicates, though, since external sends aren't deduplicated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rate limiting
&lt;/h2&gt;

&lt;p&gt;There's no per-user or per-service rate limiter today. The concurrency caps and circuit breakers contain the load. If spam protection ever becomes a requirement, it would be a new layer in front of intake.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this leaves us
&lt;/h2&gt;

&lt;p&gt;Stability here comes from putting limits on things: capped async work, providers that fail fast, and failure handling that stays local to one send. None of it is fancy. Together it stops one slow dependency from taking the whole service down.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>performance</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Notification Service, Part 6: Email, Templates and SMS</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Tue, 24 Nov 2026 03:50:23 +0000</pubDate>
      <link>https://dev.to/surhidamatya/notification-service-part-6-email-templates-and-sms-35e9</link>
      <guid>https://dev.to/surhidamatya/notification-service-part-6-email-templates-and-sms-35e9</guid>
      <description>&lt;p&gt;Push is for devices. Email and SMS cover the times a message has to reach someone outside the app: verification codes, password resets, account alerts, receipts. This post covers how email templates work and how the OTP flow uses both channels.&lt;/p&gt;

&lt;h2&gt;
  
  
  Email through Brevo
&lt;/h2&gt;

&lt;p&gt;Transactional email goes out through the Brevo API, and the design keeps content and logic apart.&lt;/p&gt;

&lt;p&gt;The content and layout live in Brevo. Marketing and product teams design the templates there, with placeholders for dynamic values like a first name or a code. The service itself keeps a mapping from an internal email type to a Brevo template ID, stored in its own database. Email types are a fixed list: forgot password, verify email, welcome, password changed, KYC updates, transaction events and monthly limit alerts, among others.&lt;/p&gt;

&lt;p&gt;To send, a listener names an email type and supplies the recipient and the placeholder values. The service looks up the template ID, builds the request and calls Brevo.&lt;/p&gt;

&lt;h3&gt;
  
  
  Managing templates
&lt;/h3&gt;

&lt;p&gt;The API can create, list, read, update and delete these mappings. Creating a mapping for an email type that already has one is rejected with a conflict. Pointing an email type at a new Brevo template is just an update, so a redesigned template goes live without a deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  When a template is missing
&lt;/h3&gt;

&lt;p&gt;If there's no mapping for an email type, the send fails with a not-found error. That's on purpose. A missing template is a setup problem and it should be loud, because the alternative is sending a blank or wrong email to a customer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Failures
&lt;/h3&gt;

&lt;p&gt;When Brevo returns an error, the service counts an email failure and throws. There's no automatic retry today.&lt;/p&gt;

&lt;h2&gt;
  
  
  SMS through Twilio
&lt;/h2&gt;

&lt;p&gt;SMS is used for OTPs and a few reminder messages. The Twilio client has explicit connect and read timeouts (5 and 10 seconds), so a hung call is aborted and doesn't tie up a thread forever. It also has a circuit breaker on the send call, with the same thresholds as push.&lt;/p&gt;

&lt;p&gt;In local development, sending is switched off and the request is only logged.&lt;/p&gt;

&lt;h2&gt;
  
  
  The OTP flow
&lt;/h2&gt;

&lt;p&gt;An OTP request arrives as an event on the send-OTP topic. One listener handles it and picks the channel from the payload. If the request has an email address, it sends a verification email through the Brevo template for that type, with the code and first name as placeholders. If not, it sends an SMS through Twilio.&lt;/p&gt;

&lt;p&gt;After a successful SMS the service publishes an OTP status update event, so the authentication side knows the code went out. That publish happens outside the circuit breaker on purpose. If it were inside, a Kafka outage could look like a Twilio failure, and an SMS that was actually delivered could be recorded as failed.&lt;/p&gt;

&lt;p&gt;The listener catches and logs any error during an OTP send, so Kafka doesn't redeliver a failed OTP. The user just asks for a new code, which is how OTPs normally behave anyway.&lt;/p&gt;

&lt;h2&gt;
  
  
  Slack for operators
&lt;/h2&gt;

&lt;p&gt;Some events are for the people running the platform, not for customers. Those go to Slack through a webhook: error alerts from other services and general notification events, formatted into readable messages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this leaves us
&lt;/h2&gt;

&lt;p&gt;Content stays in Brevo and the service only maps types to templates, so template changes are quick and low-risk. SMS has timeouts and a breaker around it, and the OTP flow keeps the provider call separate from the status publish so each failure is blamed on the right thing.&lt;/p&gt;

</description>
      <category>api</category>
      <category>backend</category>
      <category>architecture</category>
      <category>security</category>
    </item>
    <item>
      <title>Notification Service, Part 5: Push with Firebase</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Tue, 24 Nov 2026 03:50:04 +0000</pubDate>
      <link>https://dev.to/surhidamatya/notification-service-part-5-push-with-firebase-1n66</link>
      <guid>https://dev.to/surhidamatya/notification-service-part-5-push-with-firebase-1n66</guid>
      <description>&lt;p&gt;Push notifications reach iOS and Android through Firebase Cloud Messaging (FCM). The service never talks to a phone directly. It hands the message to Firebase, and Firebase delivers it using each device's token. This post covers how that call is made and what happens to bad tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where tokens come from
&lt;/h2&gt;

&lt;p&gt;Device tokens arrive inside the Kafka event. The owning service attaches the user's active tokens when it publishes. People have more than one device, so an event often carries a list.&lt;/p&gt;

&lt;p&gt;An event with no tokens isn't an error. The listener records the delivery status as &lt;code&gt;SKIPPED&lt;/code&gt; and moves on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multicast: one call, many devices
&lt;/h2&gt;

&lt;p&gt;For a list of tokens the service uses Firebase's multicast send. One call carries the message to every token, and the response reports success or failure per token, in request order. The service uses that to count successes and failures for each token, so metrics count devices that got the message, whatever the number of calls. It also tells the service exactly which tokens failed.&lt;/p&gt;

&lt;p&gt;Single-token and topic sends exist as well. The manual push endpoint uses them, for example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dead tokens
&lt;/h2&gt;

&lt;p&gt;Tokens go stale when an app is uninstalled or reinstalled, and Firebase reports that per token. The service treats two cases as dead: the token is reported as unregistered, or it's rejected as invalid in the specific way Firebase reports a malformed or expired token.&lt;/p&gt;

&lt;p&gt;For each dead token the service publishes an &lt;code&gt;unregistered-fcm-token&lt;/code&gt; event to Kafka. The service that owns the user's device records consumes it and deactivates the token. The notification service never stores or edits tokens. It reports what it learned and leaves the data with its owner. Other failures, like a temporary Firebase problem, don't trigger any token removal.&lt;/p&gt;

&lt;h2&gt;
  
  
  A slow or failing provider
&lt;/h2&gt;

&lt;p&gt;Firebase calls sit behind a circuit breaker. If at least half of the last 20 calls fail, or calls are consistently slower than 5 seconds, the breaker opens for 30 seconds. While it's open, calls fail immediately instead of waiting on a struggling provider. After the 30 seconds a few test calls go through, and the breaker closes again if they succeed.&lt;/p&gt;

&lt;p&gt;When it's open, the service records the failure for the affected devices and logs it. It doesn't crash and it doesn't block other events.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the listener records
&lt;/h2&gt;

&lt;p&gt;After the attempt, the listener sets the stored notification's delivery status to &lt;code&gt;SENT&lt;/code&gt; or &lt;code&gt;FAILED&lt;/code&gt;. That update runs asynchronously on the capped executor from Part 7, so it doesn't slow down the main flow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this leaves us
&lt;/h2&gt;

&lt;p&gt;Push is a thin layer with a few guards: one multicast call per user, per-token results feeding the metrics, dead tokens reported by event for their owner to clean up, and a circuit breaker so a Firebase outage can't drag the service down. Failed pushes aren't retried automatically today.&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>mobile</category>
      <category>backend</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Notification Service, Part 4: Idempotent Storage and the Timeline</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Tue, 24 Nov 2026 03:49:47 +0000</pubDate>
      <link>https://dev.to/surhidamatya/notification-service-part-4-idempotent-storage-and-the-timeline-5hce</link>
      <guid>https://dev.to/surhidamatya/notification-service-part-4-idempotent-storage-and-the-timeline-5hce</guid>
      <description>&lt;p&gt;The in-app timeline is what a user sees when they open the notification list. It has to stay correct when Kafka delivers the same event twice. Newest items go first, the unread count has to be instant, and old items have to clean themselves up. This post covers both halves: how duplicates get rejected, and how the DynamoDB table is shaped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part A: Idempotency
&lt;/h2&gt;

&lt;p&gt;Kafka promises at-least-once delivery, not exactly-once. After a restart, a rebalance or a retry, the same event can arrive again. Without protection the user sees duplicates and the unread badge drifts upward.&lt;/p&gt;

&lt;h3&gt;
  
  
  A deterministic notification ID
&lt;/h3&gt;

&lt;p&gt;The service builds the notification ID from the event's &lt;code&gt;eventId&lt;/code&gt;. It hashes the &lt;code&gt;eventId&lt;/code&gt; with SHA-256 and keeps the first 32 hex characters. The same event always gives the same ID, so a duplicate is recognisable without a lookup. Events with no &lt;code&gt;eventId&lt;/code&gt; or no &lt;code&gt;userId&lt;/code&gt; are skipped and logged.&lt;/p&gt;

&lt;h3&gt;
  
  
  One atomic transaction
&lt;/h3&gt;

&lt;p&gt;Storing a notification is a single DynamoDB transaction with three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A marker item for that notification ID, with a condition that it must not already exist.&lt;/li&gt;
&lt;li&gt;The notification item itself.&lt;/li&gt;
&lt;li&gt;An increment of the user's unread counter.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the marker is already there, DynamoDB cancels the whole transaction. The service reads that as "duplicate", logs it and returns without an error. The counter update sits in the same transaction, so a duplicate can't bump the unread count a second time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why it holds up
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;There's no race window. The guard and the write succeed or fail together, so two concurrent copies can't both get through.&lt;/li&gt;
&lt;li&gt;It works across time. The marker lives as long as the notification does, so a late retry still gets caught.&lt;/li&gt;
&lt;li&gt;Real errors still surface. Only a failed marker condition counts as a duplicate. Any other failure is counted, logged and rethrown, so Kafka's error handling takes over.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Where the guarantee stops
&lt;/h3&gt;

&lt;p&gt;This protects the stored timeline: one event gives at most one stored notification and a correct unread count. It doesn't make push and email exactly-once. After the store step the listener still sends the push or email, even if the store said "duplicate". So external sends are at-least-once.&lt;/p&gt;

&lt;p&gt;There's also a catch in how the delivery status is updated afterwards. It uses the sort key returned by the store step, and that key includes a timestamp taken when the notification was built. On a duplicate, the key that comes back is the new one, not the one that was stored. The status update then points at an item that doesn't exist, and a DynamoDB update creates a missing item instead of failing. The result is a stray item holding only that key and a delivery status.&lt;/p&gt;

&lt;p&gt;From reading the code, I'd expect that stray item to show up in the user's timeline and never expire, because it has no time-to-live. Meanwhile the real notification's status doesn't get updated. I haven't reproduced it, so treat it as a known gap. Returning the stored key on a duplicate, or skipping the status update when the store reports one, would close it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part B: Table design
&lt;/h2&gt;

&lt;h3&gt;
  
  
  One partition per user
&lt;/h3&gt;

&lt;p&gt;Everything for a user lives under the partition key &lt;code&gt;USER#&amp;lt;userId&amp;gt;&lt;/code&gt;, and the sort key tells the items apart:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;NOTIF#&amp;lt;reverseTimestamp&amp;gt;#&amp;lt;notificationId&amp;gt;&lt;/code&gt; is a notification.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;META&lt;/code&gt; is a per-user summary: unread count, last notification time, last "read all" time.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DEDUP#&amp;lt;notificationId&amp;gt;&lt;/code&gt; is the idempotency marker.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reading a timeline is one query against one partition.&lt;/p&gt;

&lt;h3&gt;
  
  
  Newest first without sorting
&lt;/h3&gt;

&lt;p&gt;DynamoDB returns items in sort-key order. The timestamp in the sort key is stored reversed (a maximum value minus the creation time), so newer items come first and nothing has to be sorted.&lt;/p&gt;

&lt;h3&gt;
  
  
  The unread list: a sparse index
&lt;/h3&gt;

&lt;p&gt;Unread notifications carry two extra attributes that feed a secondary index, GSI1. Read ones don't have those attributes, so they aren't in the index at all. Marking a notification as read removes the attributes and the item drops out of the index. That means the unread query only ever touches unread items, however long the history gets.&lt;/p&gt;

&lt;h3&gt;
  
  
  The unread counter
&lt;/h3&gt;

&lt;p&gt;The count sits on the &lt;code&gt;META&lt;/code&gt; item, so reading it is a single key lookup.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storing a notification increments it, in the same transaction as the write.&lt;/li&gt;
&lt;li&gt;Marking one as read decrements it, with a condition that it must be above zero, so it can't go negative.&lt;/li&gt;
&lt;li&gt;"Mark all as read" updates only the &lt;code&gt;META&lt;/code&gt; item (count to zero, time recorded). It doesn't rewrite every notification, so it costs the same for 5 notifications or 5,000.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Pagination without leaking internals
&lt;/h3&gt;

&lt;p&gt;DynamoDB's "last evaluated key" gets encoded into an opaque, URL-safe token. Clients send it back unchanged to get the next page and never see a key name. The table design can change later without breaking the API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Expiry
&lt;/h3&gt;

&lt;p&gt;Each notification has a time-to-live of 30 days from creation, plus a random extra of up to 24 hours. The random part spreads deletions across the day instead of bunching them up. User preferences are in a separate table.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this leaves us
&lt;/h2&gt;

&lt;p&gt;Deterministic IDs and an atomic conditional write give the timeline solid duplicate protection. The key design makes the common reads cheap: one query for the timeline, a sparse index for unread, one lookup for the count.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>dynamodb</category>
      <category>backend</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Notification Service, Part 3: Event-Driven Intake</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Tue, 24 Nov 2026 03:49:24 +0000</pubDate>
      <link>https://dev.to/surhidamatya/notification-service-part-3-event-driven-intake-5h13</link>
      <guid>https://dev.to/surhidamatya/notification-service-part-3-event-driven-intake-5h13</guid>
      <description>&lt;p&gt;The earlier overview post showed the notification flow as a diagram. This series opens each box and looks at how it works in the real service. We start at the front door: how an event turns into a notification.&lt;/p&gt;

&lt;h2&gt;
  
  
  The core idea
&lt;/h2&gt;

&lt;p&gt;Other services never send notifications themselves. When something happens that a user should hear about (a KYC status change, a transaction update, an account lock, a password change, an OTP request), the service that owns it publishes an event to Kafka. The notification service consumes those events and decides what to send and where.&lt;/p&gt;

&lt;p&gt;That keeps business logic and delivery apart. The service that moves money has no idea what a push token or an SMS provider is. The notification service has no idea how a transaction works. Neither has to.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an event carries
&lt;/h2&gt;

&lt;p&gt;Every event type has its own Kafka topic and its own message shape, but they share some fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An &lt;code&gt;eventId&lt;/code&gt;, unique per event. Idempotency depends on it (Part 4).&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;userId&lt;/code&gt;, the person the notification is for.&lt;/li&gt;
&lt;li&gt;The message itself: a title and a body.&lt;/li&gt;
&lt;li&gt;Delivery details: FCM device tokens for push, an email address for email.&lt;/li&gt;
&lt;li&gt;Sometimes a priority.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The delivery details travel inside the event. At send time the notification service doesn't call anyone to look up a token or an address.&lt;/p&gt;

&lt;h2&gt;
  
  
  One listener per event type
&lt;/h2&gt;

&lt;p&gt;Each topic gets its own listener class and its own container factory. A listener is small. It receives one event, validates it and hands it to whichever channels that event needs. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A KYC workflow event stores an in-app notification and sends a push.&lt;/li&gt;
&lt;li&gt;An OTP request sends an SMS or an email.&lt;/li&gt;
&lt;li&gt;An error alert from another service goes to Slack.&lt;/li&gt;
&lt;li&gt;A forgot-password event sends a transactional email.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since each listener stands alone, you can change, pause or fix one event type without touching the rest.&lt;/p&gt;

&lt;h2&gt;
  
  
  How parallelism works
&lt;/h2&gt;

&lt;p&gt;All the listeners share one Kafka consumer group. Kafka gives each topic partition to exactly one consumer in the group at a time, which has two consequences.&lt;/p&gt;

&lt;p&gt;Order holds within a partition, because events on the same partition are handled one after another. And scaling means adding replicas: more instances spread the partitions over more consumers. The listener factories don't raise the thread count per listener, so throughput grows with partitions and replicas, not with threads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Messages that can't be parsed
&lt;/h2&gt;

&lt;p&gt;The consumers use an error-handling deserializer. If a message is malformed, it becomes an error the framework deals with. It doesn't crash the listener loop, so one bad message can't block everything queued behind it on that partition.&lt;/p&gt;

&lt;h2&gt;
  
  
  What intake doesn't do
&lt;/h2&gt;

&lt;p&gt;There's no rate limiting here. Overload protection comes later in the pipeline, through capped concurrency and circuit breakers (Part 7). The intake layer also doesn't check user preferences before sending. Today the event decides which channels get used.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this leaves us
&lt;/h2&gt;

&lt;p&gt;Intake is deliberately plain: a topic and a listener per event type, one consumer group for scale, and every delivery detail inside the event. Next up is what happens when the same event shows up twice, and how the in-app timeline is stored.&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>architecture</category>
      <category>backend</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Colors in Programming, Part 3: Alpha Blending</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:27:32 +0000</pubDate>
      <link>https://dev.to/surhidamatya/colors-in-programming-part-3-alpha-blending-3h1d</link>
      <guid>https://dev.to/surhidamatya/colors-in-programming-part-3-alpha-blending-3h1d</guid>
      <description>&lt;p&gt;Part 1 covered RGB. Part 2 added alpha. Now the question that's been hanging: if you put 50% black on a white background, what color does the user see?&lt;/p&gt;

&lt;h2&gt;
  
  
  A transparent color has no fixed look
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;#80000000&lt;/code&gt; is roughly half-opaque black. Over white it looks gray. Over blue it looks dark blue. Over red, dark red. The color on its own doesn't decide the result. What's behind it does.&lt;/p&gt;

&lt;p&gt;The color on top is the foreground, the one underneath is the background.&lt;/p&gt;

&lt;h2&gt;
  
  
  The formula
&lt;/h2&gt;

&lt;p&gt;For each channel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;result = foreground × alpha + background × (1 - alpha)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alpha here is 0.0 to 1.0, so 50% is 0.5. At 0.5, foreground and background contribute equally.&lt;/p&gt;

&lt;h2&gt;
  
  
  50% black over white
&lt;/h2&gt;

&lt;p&gt;Take one channel. White is 255, black is 0, alpha is 0.5:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 × 0.5 + 255 × 0.5 = 127.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That rounds to 128, or &lt;code&gt;80&lt;/code&gt; in hex. The result is &lt;code&gt;#808080&lt;/code&gt;, a mid gray.&lt;/p&gt;

&lt;p&gt;At 20% black over white:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 × 0.2 + 255 × 0.8 = 204
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;204 is &lt;code&gt;CC&lt;/code&gt;, so &lt;code&gt;#CCCCCC&lt;/code&gt;, a light gray. At 80%:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 × 0.8 + 255 × 0.2 = 51
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;51 is &lt;code&gt;33&lt;/code&gt;, so &lt;code&gt;#333333&lt;/code&gt;, quite dark.&lt;/p&gt;

&lt;h2&gt;
  
  
  Doing it for all three channels
&lt;/h2&gt;

&lt;p&gt;Run the same formula on red, green and blue separately. Say the foreground is 50% opaque red, &lt;code&gt;RGB(255, 0, 0)&lt;/code&gt;, over white, &lt;code&gt;RGB(255, 255, 255)&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Red:   255 × 0.5 + 255 × 0.5 = 255
Green:   0 × 0.5 + 255 × 0.5 = 127.5 → 128
Blue:    0 × 0.5 + 255 × 0.5 = 127.5 → 128
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That gives &lt;code&gt;RGB(255, 128, 128)&lt;/code&gt;, or &lt;code&gt;#FF8080&lt;/code&gt;. A light pink.&lt;/p&gt;

&lt;h2&gt;
  
  
  Same overlay, different result
&lt;/h2&gt;

&lt;p&gt;This is why the same code can look different in different places. &lt;code&gt;#80000000&lt;/code&gt; over white comes out around &lt;code&gt;#808080&lt;/code&gt;. Over blue, &lt;code&gt;#0000FF&lt;/code&gt;, it comes out around &lt;code&gt;#000080&lt;/code&gt;. The overlay didn't change. The background did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overlays and gradients
&lt;/h2&gt;

&lt;p&gt;The usual use is readability. You have a photo with white text on it, and a bright patch of sky makes the text hard to read. Put a &lt;code&gt;#80000000&lt;/code&gt; layer between them. The image gets darker, the text stays white, contrast goes up.&lt;/p&gt;

&lt;p&gt;Gradients use the same trick. Keep the RGB fixed at black and only change alpha:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#00000000   top, invisible
#80000000   middle, half
#FF000000   bottom, solid black
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's a gradient of opacity, not of hue. It's the standard way to make a caption area at the bottom of an image.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layers
&lt;/h2&gt;

&lt;p&gt;Real interfaces stack several layers: text on a card, on an overlay, on an image, on a page background. Each can have its own alpha, and the renderer blends them from back to front. A color you see on screen may be the result of four or five blends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Source color vs rendered color
&lt;/h2&gt;

&lt;p&gt;This one catches people. Say you've got &lt;code&gt;#80000000&lt;/code&gt; over a blue background, and you point a color picker at the screen. It reports something like &lt;code&gt;#000080&lt;/code&gt;. It's tempting to conclude the designer chose dark blue. They didn't. They used 50% black over blue.&lt;/p&gt;

&lt;p&gt;A color picker reads the final rendered pixel. Your code specifies the source color. When something looks off, ask which one you're looking at.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two mistakes to avoid
&lt;/h2&gt;

&lt;p&gt;First, opacity vs transparency again. "20% transparent black" is 80% opaque, alpha &lt;code&gt;CC&lt;/code&gt;. "20% opaque black" is alpha &lt;code&gt;33&lt;/code&gt;. Those are very different overlays.&lt;/p&gt;

&lt;p&gt;Second, assuming alpha position. &lt;code&gt;#80FF0000&lt;/code&gt; in ARGB is &lt;code&gt;#FF000080&lt;/code&gt; in RRGGBBAA. Copying an eight-digit code between platforms without checking is a good way to get a color that's wrong in a confusing way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Debugging a color
&lt;/h2&gt;

&lt;p&gt;Don't squint at the whole string. Split it. For &lt;code&gt;#B4555555&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;B4 55 55 55
 A  R  G  B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What's the alpha?&lt;/li&gt;
&lt;li&gt;What's the RGB?&lt;/li&gt;
&lt;li&gt;What's behind it?&lt;/li&gt;
&lt;li&gt;Is there another layer?&lt;/li&gt;
&lt;li&gt;Does this platform use AARRGGBB or RRGGBBAA?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The whole chain
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RGB → hex → alpha → opacity → blending → rendered color
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;#FF0000&lt;/code&gt; is red. &lt;code&gt;#80FF0000&lt;/code&gt; is about 50% opaque red. What you see depends on what's under it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cheat sheet
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RGB    #RRGGBB     #FF0000 = red
ARGB   #AARRGGBB   #80FF0000 = ~50% opaque red

alpha   = opacity × 255 / 100
opacity = alpha × 100 / 255

100% FF   90% E6   80% CC   70% B3   60% 99   50% 80
 40% 66   30% 4D   20% 33   10% 1A    0% 00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check each platform's alpha order. Some use &lt;code&gt;#AARRGGBB&lt;/code&gt;, some use &lt;code&gt;#RRGGBBAA&lt;/code&gt;, and some take alpha separately.&lt;/p&gt;

&lt;p&gt;You don't need to memorize hex colors. If you can look at &lt;code&gt;#B4555555&lt;/code&gt; and see &lt;code&gt;B4 | 55 | 55 | 55&lt;/code&gt; as alpha, red, green, blue, you understand how they're built, and that's enough.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
      <category>design</category>
    </item>
    <item>
      <title>Colors in Programming, Part 2: Alpha, Opacity and Transparency</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:26:19 +0000</pubDate>
      <link>https://dev.to/surhidamatya/colors-in-programming-part-2-alpha-opacity-and-transparency-49ok</link>
      <guid>https://dev.to/surhidamatya/colors-in-programming-part-2-alpha-opacity-and-transparency-49ok</guid>
      <description>&lt;p&gt;In part 1, a color was &lt;code&gt;#RRGGBB&lt;/code&gt;. &lt;code&gt;#FF0000&lt;/code&gt; is red.&lt;/p&gt;

&lt;p&gt;But what if you want red that's only half visible? That's what alpha is for. You've probably seen codes like these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#80FF0000
#80000000
#80FFFFFF
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The extra two characters aren't another color. They're alpha.&lt;/p&gt;

&lt;h2&gt;
  
  
  What alpha does
&lt;/h2&gt;

&lt;p&gt;RGB says what color it is. Alpha says how opaque it is, meaning how much of it shows over whatever is behind. It uses the same range as the other channels, 0 to 255, or 00 to FF in hex:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;00 = fully transparent
FF = fully opaque
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Opacity vs transparency
&lt;/h2&gt;

&lt;p&gt;These are opposites, and mixing them up causes real bugs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100% opaque = 0% transparent
50% opaque  = 50% transparent
20% opaque  = 80% transparent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a designer says "make it 20% transparent", that's 80% opaque. Ask which one they mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  ARGB
&lt;/h2&gt;

&lt;p&gt;A common 32-bit layout puts alpha first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#AARRGGBB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So &lt;code&gt;#80FF0000&lt;/code&gt; splits into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;80 FF 00 00
 A  R  G  B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's red, at roughly 50% opacity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why 80 is about 50%
&lt;/h2&gt;

&lt;p&gt;Alpha runs from 0 to 255, so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alpha = opacity × 255 / 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For 50% that's 127.5, which rounds to 128, which is &lt;code&gt;0x80&lt;/code&gt; in hex. For 25% it's 63.75, rounded to 64, which is &lt;code&gt;0x40&lt;/code&gt;. So &lt;code&gt;#40FF0000&lt;/code&gt; is about 25% opaque red.&lt;/p&gt;

&lt;p&gt;Here's a cheat table so you don't have to do the math each time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100%  FF      50%  80
 90%  E6      40%  66
 80%  CC      30%  4D
 70%  B3      20%  33
 60%  99      10%  1A
                0%  00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Going the other way
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;opacity = alpha × 100 / 255
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take &lt;code&gt;B3&lt;/code&gt;. That's 11 × 16 + 3 = 179, and 179 × 100 / 255 is about 70%.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decoding a few
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;#80FFFFFF&lt;/code&gt; splits into &lt;code&gt;80 FF FF FF&lt;/code&gt;. Alpha is about 50%, RGB is white. So: half-opaque white.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;#80000000&lt;/code&gt; is &lt;code&gt;80 00 00 00&lt;/code&gt;. Half-opaque black. This one shows up constantly as an overlay.&lt;/p&gt;

&lt;p&gt;Here's the one that started this series for me, &lt;code&gt;#B4555555&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;B4 55 55 55
 A  R  G  B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The color is &lt;code&gt;#555555&lt;/code&gt;, a mid-dark gray. Alpha is B4, which is 180, which is about 71%. So it's 71% opaque gray.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why deleting characters changes everything
&lt;/h2&gt;

&lt;p&gt;Say you take &lt;code&gt;#B4555555&lt;/code&gt; and chop off the last two characters, hoping to drop the transparency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#B45555
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That doesn't remove alpha. It changes how the string is parsed. Six digits means &lt;code&gt;RRGGBB&lt;/code&gt;, so now red is B4, green is 55, blue is 55, and nothing says anything about alpha. You've got a fully opaque, reddish color. It's a different color entirely.&lt;/p&gt;

&lt;p&gt;Count the digits and split first. Don't edit hex by feel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Opacity isn't a color
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;#FF0000&lt;/code&gt; and &lt;code&gt;#80FF0000&lt;/code&gt; are the same color: red. The only difference is that the second one says how much of it to show. RGB is what color, alpha is how opaque.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it matters
&lt;/h2&gt;

&lt;p&gt;A transparent color needs something behind it to be useful. Put 50% black over a blue background and you get a darker blue. The black doesn't replace the blue, it blends with it. That's how image overlays, modal backdrops, shadows, disabled controls and scrims work. Part 3 shows the actual math.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ordering problem
&lt;/h2&gt;

&lt;p&gt;Not everyone agrees where alpha goes. Half-opaque red can be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#80FF0000   (AARRGGBB)
#FF000080   (RRGGBBAA)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same components, different positions. Android uses ARGB. CSS accepts &lt;code&gt;#RRGGBBAA&lt;/code&gt; and also &lt;code&gt;rgba(255, 0, 0, 0.5)&lt;/code&gt;. Flutter uses ARGB-style integers like &lt;code&gt;0x80FF0000&lt;/code&gt;. Some APIs skip hex and take alpha as a separate parameter, either 0 to 255 or 0.0 to 1.0. Check what the API you're using expects before pasting a code across.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Alpha is a fourth channel. RGB says what color, alpha says how opaque. In &lt;code&gt;#AARRGGBB&lt;/code&gt;, &lt;code&gt;#80FF0000&lt;/code&gt; is 50% alpha, full red, no green, no blue. Convert with &lt;code&gt;alpha = opacity × 255 / 100&lt;/code&gt; and back with &lt;code&gt;opacity = alpha × 100 / 255&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What's left is the question of what actually happens when a transparent color lands on another one. That's part 3.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
      <category>design</category>
    </item>
    <item>
      <title>Colors in Programming, Part 1: RGB and Hex</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:25:09 +0000</pubDate>
      <link>https://dev.to/surhidamatya/colors-in-programming-part-1-rgb-and-hex-na3</link>
      <guid>https://dev.to/surhidamatya/colors-in-programming-part-1-rgb-and-hex-na3</guid>
      <description>&lt;p&gt;Sooner or later you run into colors written like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#FF0000
#336699
#FFFFFF
#000000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They look random. They aren't. Once you know two things, RGB and hexadecimal, you can read most of them on sight.&lt;/p&gt;

&lt;p&gt;This is part 1 of 3. Part 2 covers alpha (transparency) and part 3 covers what happens when a transparent color sits on top of another one. Here I only want to answer one question: how does a computer store a color?&lt;/p&gt;

&lt;h2&gt;
  
  
  Three numbers
&lt;/h2&gt;

&lt;p&gt;Most screens work with the RGB model: red, green and blue. Each channel gets a value from 0 to 255, so a color is just three numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RGB(255, 0, 0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's red at full strength, no green, no blue. &lt;code&gt;RGB(0, 255, 0)&lt;/code&gt; is pure green and &lt;code&gt;RGB(0, 0, 255)&lt;/code&gt; is pure blue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why 255?
&lt;/h2&gt;

&lt;p&gt;Because a channel is usually stored in 8 bits. Eight bits give you 2⁸ = 256 values, and since counting starts at zero, they run from 0 to 255:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;00000000 = 0
11111111 = 255
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three channels of 256 levels each is 256 × 256 × 256 = 16,777,216 possible colors. That's where "24-bit color" comes from: 8 + 8 + 8 = 24 bits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why hex?
&lt;/h2&gt;

&lt;p&gt;You could write &lt;code&gt;RGB(255, 0, 0)&lt;/code&gt; everywhere, and people do. Hex is shorter, and it lines up neatly with the 8-bit values.&lt;/p&gt;

&lt;p&gt;Hexadecimal is base 16. It uses the digits 0 to 9, then letters for the next six:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A = 10   B = 11   C = 12
D = 13   E = 14   F = 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two hex digits cover 00 to FF, which is 0 to 255. That's exactly one channel. So a color is three pairs, one per channel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#RRGGBB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reading some codes
&lt;/h2&gt;

&lt;p&gt;Split &lt;code&gt;#FF0000&lt;/code&gt; into pairs and label them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FF  00  00
R   G   B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Red is FF (255), green is 0, blue is 0. Pure red.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;#00FF00&lt;/code&gt; is &lt;code&gt;00 FF 00&lt;/code&gt;, so pure green. &lt;code&gt;#0000FF&lt;/code&gt; is &lt;code&gt;00 00 FF&lt;/code&gt;, so pure blue.&lt;/p&gt;

&lt;p&gt;White is &lt;code&gt;#FFFFFF&lt;/code&gt;, everything at maximum. Black is &lt;code&gt;#000000&lt;/code&gt;, everything at zero. Mixing channels gives the rest: &lt;code&gt;#FFFF00&lt;/code&gt; is red plus green with no blue, which is yellow. &lt;code&gt;#FF00FF&lt;/code&gt; is magenta and &lt;code&gt;#00FFFF&lt;/code&gt; is cyan.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decoding one you've never seen
&lt;/h2&gt;

&lt;p&gt;Take &lt;code&gt;#336699&lt;/code&gt;. Split it into &lt;code&gt;33 66 99&lt;/code&gt; and convert each pair to decimal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;33 hex = 51
66 hex = 102
99 hex = 153
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So it's &lt;code&gt;RGB(51, 102, 153)&lt;/code&gt;, a muted blue. You don't have to remember that. You can work it out, and that's the skill worth having.&lt;/p&gt;

&lt;h2&gt;
  
  
  Converting hex by hand
&lt;/h2&gt;

&lt;p&gt;Each pair is two digits in base 16, so the left digit counts sixteens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3A = 3 × 16 + 10 = 58
FF = 15 × 16 + 15 = 255
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is also why FF means "maximum". F is the biggest single digit (15), and FF is the biggest two-digit number (255). Every channel runs from 00 (off) to FF (full).&lt;/p&gt;

&lt;h2&gt;
  
  
  The same idea everywhere
&lt;/h2&gt;

&lt;p&gt;RGB isn't tied to one language. You'll meet it in CSS, Android, iOS, Flutter, React Native, game engines and image libraries. The syntax changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nn"&gt;#FF0000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flutter wants an integer like &lt;code&gt;0xFFFF0000&lt;/code&gt;. Underneath it's the same three numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  A warning about eight digits
&lt;/h2&gt;

&lt;p&gt;Six-digit colors are &lt;code&gt;RRGGBB&lt;/code&gt; pretty much everywhere. Eight-digit ones are a mess. Some platforms put the extra pair first (&lt;code&gt;AARRGGBB&lt;/code&gt;), others put it last (&lt;code&gt;RRGGBBAA&lt;/code&gt;). Part 2 is about that extra pair.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to take away
&lt;/h2&gt;

&lt;p&gt;Don't memorize hex codes. Remember the shape, &lt;code&gt;#RRGGBB&lt;/code&gt;, with each pair running from 00 to FF. Then &lt;code&gt;#FF0000&lt;/code&gt; is red, &lt;code&gt;#00FF00&lt;/code&gt; green, &lt;code&gt;#0000FF&lt;/code&gt; blue, &lt;code&gt;#FFFFFF&lt;/code&gt; white and &lt;code&gt;#000000&lt;/code&gt; black, and anything else you can split and convert.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
      <category>design</category>
    </item>
    <item>
      <title>Multipart Image Upload, Part 5: Production Architecture and Cross-Platform Implementation</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:18:11 +0000</pubDate>
      <link>https://dev.to/surhidamatya/multipart-image-upload-part-5-production-architecture-and-cross-platform-implementation-2oai</link>
      <guid>https://dev.to/surhidamatya/multipart-image-upload-part-5-production-architecture-and-cross-platform-implementation-2oai</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Multipart Image Upload: A Practical Guide for Web, Mobile and Backend&lt;/strong&gt;&lt;br&gt;
Part 1: Understanding Chunked Multipart Upload&lt;br&gt;
Part 2: Chunking the Image Locally&lt;br&gt;
Part 3: Building the Multipart Upload API&lt;br&gt;
Part 4: Making Uploads Reliable and Resumable&lt;br&gt;
Part 5: Production Architecture and Cross-Platform Implementation (this post)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We have the protocol, the chunking, the server and the retry logic. This last part puts them into something you could run in production, shows how each platform plugs in, and lists what else needs handling before real users touch it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        Web          Mobile
          \           /
           ▼         ▼
          API Gateway
                │
                ▼
         Upload Service
                │
      ┌─────────┴─────────┐
      ▼                   ▼
 PostgreSQL          Object Storage
 Upload state        S3 / Azure Blob
                          │
                          ▼
                     Final Image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each piece has one job.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;API gateway&lt;/strong&gt; terminates TLS, authenticates, rate-limits and enforces body-size limits before traffic reaches your code.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;upload service&lt;/strong&gt; is the Spring Boot app from part 3. It validates requests, owns the upload lifecycle and talks to the other two. Keep it stateless so you can run several instances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PostgreSQL&lt;/strong&gt; holds upload state: &lt;code&gt;uploadId&lt;/code&gt;, owner, file name, declared size, &lt;code&gt;totalParts&lt;/code&gt;, expected checksum, status, expiry, and one row per received part. This replaces "look at the files on disk" from part 3, which only works on one machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object storage&lt;/strong&gt; holds the bytes, both temporary parts and the final image. Local disk is fine on a single server and breaks the moment you add a second one, because a request for part 4 may hit a different instance than part 3 did.&lt;/p&gt;

&lt;p&gt;A shortcut worth knowing: S3 and Azure Blob have native multipart upload (S3's &lt;code&gt;CreateMultipartUpload&lt;/code&gt; and &lt;code&gt;UploadPart&lt;/code&gt;, Azure's block blobs with &lt;code&gt;PutBlock&lt;/code&gt; and &lt;code&gt;PutBlockList&lt;/code&gt;). They use the same ideas: part numbers, idempotent parts, a final complete call. A common design has your service authorize the upload and hand out presigned URLs per part, so chunks go straight to storage and skip your servers. Building it yourself, as this series does, is a good way to learn how it works, and it's the right call when you need your own processing in the path.&lt;/p&gt;

&lt;h2&gt;
  
  
  How each platform fits
&lt;/h2&gt;

&lt;p&gt;The server contract is the same for everyone. Only the way each client reads bytes and builds the request differs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web (React / Next.js):&lt;/strong&gt; &lt;code&gt;File.slice()&lt;/code&gt;, then &lt;code&gt;FormData&lt;/code&gt;, then the multipart API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FormData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"partNumber"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;partNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"totalParts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalParts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"chunk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`/api/uploads/${uploadId}/parts`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't set the &lt;code&gt;Content-Type&lt;/code&gt; header yourself. The browser adds it with the right boundary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mobile (Flutter):&lt;/strong&gt; file stream, read a chunk, &lt;code&gt;MultipartRequest&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;MultipartRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;Uri&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'$baseUrl/api/uploads/$uploadId/parts'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'partNumber'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'$partNumber'&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'totalParts'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'$totalParts'&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;MultipartFile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'chunk'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'chunk'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Java (Spring Boot, server side):&lt;/strong&gt; &lt;code&gt;MultipartFile&lt;/code&gt;, temporary storage, object storage. This is the controller from part 3. In production, swap the local &lt;code&gt;transferTo&lt;/code&gt; for a stream into object storage and record the part in PostgreSQL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python:&lt;/strong&gt; &lt;code&gt;requests&lt;/code&gt; with &lt;code&gt;multipart/form-data&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{base}/api/uploads/{upload_id}/parts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"partNumber"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;part_number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"totalParts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;total_parts&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"chunk"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"chunk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;.NET:&lt;/strong&gt; &lt;code&gt;HttpClient&lt;/code&gt; with &lt;code&gt;MultipartFormDataContent&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MultipartFormDataContent&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StringContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;partNumber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"partNumber"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StringContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalParts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"totalParts"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ByteArrayContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"chunk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"chunk"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;httpClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PostAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    $&lt;span class="s2"&gt;"/api/uploads/{uploadId}/parts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same endpoint and same three fields from five languages. That's what a clear protocol buys you.&lt;/p&gt;

&lt;h2&gt;
  
  
  What production needs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authenticate every call, and tie each session to its creator. User A must not be able to write parts to, read the status of, or complete user B's &lt;code&gt;uploadId&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Check the declared content type, but don't trust it. Look at the assembled file's magic bytes to confirm it really is a JPEG or PNG.&lt;/li&gt;
&lt;li&gt;Scan the final file for malware (ClamAV or a cloud scanning service) and keep it quarantined until it passes.&lt;/li&gt;
&lt;li&gt;Generate &lt;code&gt;uploadId&lt;/code&gt; on the server as a UUID, and never put client-supplied names in storage paths.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Limits and abuse&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Declare the maximum file size at creation and enforce it as parts arrive. Reject any part that would push the total over.&lt;/li&gt;
&lt;li&gt;Let the server dictate chunk size in the create response, so you can retune without shipping new clients.&lt;/li&gt;
&lt;li&gt;Rate-limit by user and IP, on part requests and on the number of open uploads per user.&lt;/li&gt;
&lt;li&gt;Cap simultaneous sessions per user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Integrity&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verify a hash per part, to reject corruption early, and a hash of the whole file at completion. The client computes the expected whole-file hash up front and sends it when creating the upload.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lifecycle and cleanup&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Give every session an expiry (24 hours is common) and refuse parts after it.&lt;/li&gt;
&lt;li&gt;Run a scheduled job that deletes the parts and rows of expired or abandoned uploads. Without one, storage grows forever and nobody notices. Object stores can also do this with lifecycle rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Operations&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Track parts received per second, retry rate, completion rate, abandonment rate, time to complete and errors by status. Put &lt;code&gt;uploadId&lt;/code&gt; on every log line so one upload can be traced end to end. A rising retry rate usually means your chunk size is too big for your users' networks.&lt;/li&gt;
&lt;li&gt;Make state transitions explicit (&lt;code&gt;CREATED&lt;/code&gt;, &lt;code&gt;UPLOADING&lt;/code&gt;, &lt;code&gt;ASSEMBLING&lt;/code&gt;, &lt;code&gt;COMPLETED&lt;/code&gt;, &lt;code&gt;FAILED&lt;/code&gt;, &lt;code&gt;EXPIRED&lt;/code&gt;), and guard &lt;code&gt;complete&lt;/code&gt; so two simultaneous calls can't both assemble the file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The full lifecycle
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          CREATE
             │
             ▼
         uploadId
             │
             ▼
        CHUNK FILE
             │
             ▼
       UPLOAD PARTS
             │
      ┌──────┴──────┐
   SUCCESS         FAIL
      │              │
      │            RETRY
      │              │
      └──────┬───────┘
             ▼
          STATUS
             │
             ▼
        ALL PARTS?
         /       \
       NO        YES
       │          │
       ▼          ▼
    Resume     COMPLETE
                  │
                  ▼
              CHECKSUM
                  │
                  ▼
            RECONSTRUCT
                  │
                  ▼
           OBJECT STORE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two loops in there. The inner one uploads parts and retries failures. The outer one checks status and resumes until nothing is missing. Only then does the client call &lt;code&gt;complete&lt;/code&gt;, and the server verifies the checksum before assembling the file into object storage.&lt;/p&gt;

&lt;h2&gt;
  
  
  The series, in short
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Answer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Why do this?&lt;/td&gt;
&lt;td&gt;Small requests are cheap to fail and retry.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;How do we split the image?&lt;/td&gt;
&lt;td&gt;Byte ranges via &lt;code&gt;ceil(size / chunkSize)&lt;/code&gt;, never smaller images.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;How does the server identify parts?&lt;/td&gt;
&lt;td&gt;Metadata (&lt;code&gt;uploadId&lt;/code&gt;, &lt;code&gt;partNumber&lt;/code&gt;), not the bytes.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;What when the network fails?&lt;/td&gt;
&lt;td&gt;Status, retry, resume, idempotent parts, bounded parallelism.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;How does it run in production?&lt;/td&gt;
&lt;td&gt;Gateway, stateless service, database state, object storage, and the safeguards around them.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If two ideas stick, make them these: a part's identity lives in its metadata, and every operation can be repeated safely.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>security</category>
      <category>aws</category>
      <category>backend</category>
    </item>
    <item>
      <title>Multipart Image Upload, Part 4: Making Uploads Reliable and Resumable</title>
      <dc:creator>Surhid Amatya</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:17:32 +0000</pubDate>
      <link>https://dev.to/surhidamatya/multipart-image-upload-part-4-making-uploads-reliable-and-resumable-3flb</link>
      <guid>https://dev.to/surhidamatya/multipart-image-upload-part-4-making-uploads-reliable-and-resumable-3flb</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Multipart Image Upload: A Practical Guide for Web, Mobile and Backend&lt;/strong&gt;&lt;br&gt;
Part 1: Understanding Chunked Multipart Upload&lt;br&gt;
Part 2: Chunking the Image Locally&lt;br&gt;
Part 3: Building the Multipart Upload API&lt;br&gt;
Part 4: Making Uploads Reliable and Resumable (this post)&lt;br&gt;
Part 5: Production Architecture and Cross-Platform Implementation&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So far the upload works when nothing goes wrong. Phones don't give you that. They go into tunnels, flip between Wi-Fi and cellular, and get backgrounded by the OS mid-request.&lt;/p&gt;

&lt;p&gt;Chunking already did the hard part: failures are now small and local. This post is about using that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retry only what failed
&lt;/h2&gt;

&lt;p&gt;Five parts are uploading and one fails:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Part 1  ✓
Part 2  ✓
Part 3  ✗
Part 4  ✓
Part 5  ✓
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With one big request the user would start over. Here only part 3 is retried. The other four are already on the server.&lt;/p&gt;

&lt;p&gt;A retry policy that holds up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retry network errors, timeouts and &lt;code&gt;5xx&lt;/code&gt; responses. Don't retry &lt;code&gt;4xx&lt;/code&gt; (the request is wrong, and sending it again won't fix that), except &lt;code&gt;408&lt;/code&gt; and &lt;code&gt;429&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Back off exponentially with jitter: roughly 1s, 2s, 4s, each with a random offset. Without jitter, clients that failed together retry together.&lt;/li&gt;
&lt;li&gt;Cap attempts per part at 3 to 5, then show an error and let the user try again.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sendWithRetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;send&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// network error or timeout: fall through to retry&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;408&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Part rejected with status ${res.status}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Out of retries"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The status endpoint
&lt;/h2&gt;

&lt;p&gt;Retrying blindly wastes requests. The client should be able to ask what the server actually has:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;uploads&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;abc&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"uploadId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"abc-123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"totalParts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"receivedParts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"missingParts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server builds this from storage (which part files exist) or from a database row per part. The server is the source of truth. The client's own memory of what it sent can be wrong: a request may have succeeded while the response got lost on the way back.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resume after a crash
&lt;/h2&gt;

&lt;p&gt;The status endpoint pays for itself here. If the user force-quits the app halfway, or closes the tab, the flow on restart is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application crashes
        ↓
Application starts
        ↓
Load saved uploadId
        ↓
GET upload status
        ↓
Find missing parts
        ↓
Upload only the missing parts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The client needs to persist very little: the &lt;code&gt;uploadId&lt;/code&gt; and a way to find the file again (a path on mobile, a re-selected file on web). Everything else comes from the server. Local storage, shared preferences or a small database all work.&lt;/p&gt;

&lt;p&gt;Check that the file hasn't changed before resuming. Compare size and modified time, or a hash saved at the start. If the user swapped the file, the old parts are useless and the upload restarts under a new &lt;code&gt;uploadId&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let sessions expire too. An upload nobody resumes should be cleaned up after, say, 24 hours. Part 5 covers that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Idempotency: what if part 3 arrives twice?
&lt;/h2&gt;

&lt;p&gt;Retries produce duplicates. The standard case: the client sends part 3, the server stores it, the response is lost. The client sees a timeout and sends part 3 again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client  → Part 3 → Server   (stored, response lost)
Client  → Part 3 → Server   (again)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server shouldn't end up with &lt;code&gt;part-3&lt;/code&gt; and &lt;code&gt;part-3-copy&lt;/code&gt;. It shouldn't reject the second request, and it shouldn't append the data twice. Sending it twice should have the same effect as sending it once.&lt;/p&gt;

&lt;p&gt;That mostly falls out of the file naming from part 3. The storage location comes from &lt;code&gt;partNumber&lt;/code&gt;, so the second write hits the same file. Writing to a temp file and moving it into place makes it safer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;partPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uploadId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;partNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTempFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getParent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"part-"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;".tmp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transferTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;StandardCopyOption&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;REPLACE_EXISTING&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;StandardCopyOption&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ATOMIC_MOVE&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the atomic move, a half-written part can't be mistaken for a finished one. If the process dies mid-write, you're left with a stray temp file for the cleanup job. You can also accept a SHA-256 header per part and verify it, so a corrupted chunk gets rejected and retried instead of stored.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sequential or parallel
&lt;/h2&gt;

&lt;p&gt;Sequential is the safe default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 → 2 → 3 → 4 → 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Parallel can be a lot faster, because several requests share the bandwidth and hide per-request latency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 ────────┐
2 ────────┤
3 ────────┼──→ Server
4 ────────┤
5 ────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The protocol already allows it. Parts are independent and identified by number.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why you need a concurrency limit
&lt;/h3&gt;

&lt;p&gt;Firing all 50 requests at once is tempting, and it goes badly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fifty streams share one link, so each is slow and more likely to time out.&lt;/li&gt;
&lt;li&gt;Browsers cap connections per host (typically 6 on HTTP/1.1), so most requests just sit in a queue.&lt;/li&gt;
&lt;li&gt;One user opening 50 connections looks like an attack on your own server.&lt;/li&gt;
&lt;li&gt;Phones pay for it in battery and memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Three or four at a time is usually about right. A small worker pool does it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;uploadAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;partNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendWithRetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;sendPart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;partNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each worker takes the next part when it finishes one, so the pool stays full and never goes past &lt;code&gt;limit&lt;/code&gt;. If a part runs out of retries, fail the run cleanly and let the user resume from status.&lt;/p&gt;

&lt;p&gt;On mobile you might drop the limit on cellular, use smaller chunks on a weak signal, and pause when the connection drops.&lt;/p&gt;

&lt;h2&gt;
  
  
  The reliable loop
&lt;/h2&gt;

&lt;p&gt;The whole client loop is short:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the upload, or reload a saved one, to get the &lt;code&gt;uploadId&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ask &lt;code&gt;/status&lt;/code&gt; for missing parts.&lt;/li&gt;
&lt;li&gt;Upload those through a bounded pool, each with retry and backoff.&lt;/li&gt;
&lt;li&gt;Ask &lt;code&gt;/status&lt;/code&gt; again. If anything is still missing, go back to step 3.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;/complete&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Every step is safe to repeat, and that's what makes the thing hold up. Part 5 zooms out to production: components, per-platform clients, and the operational side.&lt;/p&gt;

</description>
      <category>api</category>
      <category>mobile</category>
      <category>reliability</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
