<?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>Forem: Priyadharshini</title>
    <description>The latest articles on Forem by Priyadharshini (@priyadharshini_6b8f9f440f).</description>
    <link>https://forem.com/priyadharshini_6b8f9f440f</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3742567%2Fdf2681f7-d894-4b52-930b-a824a409b48d.jpg</url>
      <title>Forem: Priyadharshini</title>
      <link>https://forem.com/priyadharshini_6b8f9f440f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/priyadharshini_6b8f9f440f"/>
    <language>en</language>
    <item>
      <title>Designing Instagram Stories: From Upload to Expiry</title>
      <dc:creator>Priyadharshini</dc:creator>
      <pubDate>Fri, 30 Jan 2026 18:08:47 +0000</pubDate>
      <link>https://forem.com/priyadharshini_6b8f9f440f/designing-instagram-stories-from-upload-to-expiry-3fk2</link>
      <guid>https://forem.com/priyadharshini_6b8f9f440f/designing-instagram-stories-from-upload-to-expiry-3fk2</guid>
      <description>&lt;p&gt;Instagram Stories and WhatsApp Status look simple: upload media, show it to followers, and delete it after 24 hours. Under the hood, however, they are classic examples of ephemeral, large-scale distributed systems.&lt;/p&gt;

&lt;p&gt;In this article, we’ll walk through a high-level and low-level system design of a Stories/Status system, focusing on architecture, key components, and lifecycle management.&lt;/p&gt;

&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%2Flafc6op8avcnwx7ahj5i.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%2Flafc6op8avcnwx7ahj5i.png" alt=" " width="800" height="626"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Core Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;1.1 Functional requirements:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Users can post photo or video stories&lt;/li&gt;
&lt;li&gt;Stories expire automatically after 24 hours&lt;/li&gt;
&lt;li&gt;Visibility is restricted (followers, close friends, contacts)&lt;/li&gt;
&lt;li&gt;Viewers can see and react to stories&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;1.2 Non-functional requirements:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Low latency for feed loading&lt;/li&gt;
&lt;li&gt;High availability&lt;/li&gt;
&lt;li&gt;Horizontal scalability&lt;/li&gt;
&lt;li&gt;Eventual consistency is acceptable&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;2. High-Level Architecture (HLD)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At a high level, the system is split into independent services, each responsible for a single concern:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API Gateway – authentication, authorization, routing, rate limiting&lt;/li&gt;
&lt;li&gt;Story Service – story creation and lifecycle management&lt;/li&gt;
&lt;li&gt;Content Service – media, text, and link handling&lt;/li&gt;
&lt;li&gt;Feed Service – story feed generation&lt;/li&gt;
&lt;li&gt;Visibility Service – privacy and audience enforcement&lt;/li&gt;
&lt;li&gt;Expiration Service – 24-hour TTL handling&lt;/li&gt;
&lt;li&gt;Kafka &amp;amp; Background Workers – asynchronous processing&lt;/li&gt;
&lt;li&gt;Analytics &amp;amp; Notification Services – engagement insights and alerts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Story Creation Flow (Write Path)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;When a user posts a story:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The client sends a request through the API Gateway&lt;/li&gt;
&lt;li&gt;The Content Service returns a pre-signed upload URL&lt;/li&gt;
&lt;li&gt;The client uploads media directly to object storage (e.g., S3)&lt;/li&gt;
&lt;li&gt;The Story Service stores metadata with a 24-hour expiration timestamp&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Key design decision:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
    Media never flows through backend services. Only lightweight metadata is stored, while media is delivered via CDN.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Story Consumption Flow (Read Path)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;When a user opens the stories tray:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Feed Service fetches active stories from followed users&lt;/li&gt;
&lt;li&gt;Visibility Service filters stories based on privacy rules&lt;/li&gt;
&lt;li&gt;Expired stories are ignored&lt;/li&gt;
&lt;li&gt;Media URLs are returned to the client&lt;/li&gt;
&lt;li&gt;The client streams media directly from the CDN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This design is optimized for read-heavy traffic, which dominates story usage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Visibility and Privacy Rules&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Stories support multiple visibility modes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Followers only&lt;/li&gt;
&lt;li&gt;Close friends&lt;/li&gt;
&lt;li&gt;Contact-based visibility (WhatsApp Status)&lt;/li&gt;
&lt;li&gt;Blocked users&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;A dedicated Visibility Service enforces these rules using:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Followers / contacts graph&lt;/li&gt;
&lt;li&gt;Redis caching for fast permission checks&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By isolating visibility logic, privacy rules remain consistent and easy to evolve.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Expiration and Lifecycle Management&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Ephemeral content is treated as a first-class concern:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each story has a strict 24-hour TTL&lt;/li&gt;
&lt;li&gt;Expiration Service monitors story timestamps&lt;/li&gt;
&lt;li&gt;Expired stories trigger lifecycle events&lt;/li&gt;
&lt;li&gt;Expired content is no longer served&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;This guarantees correctness even under high traffic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Event-Driven Cleanup Using Kafka&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kafka is used to decouple lifecycle events from cleanup logic.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Typical events include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;story_created&lt;/li&gt;
&lt;li&gt;story_expired&lt;/li&gt;
&lt;li&gt;story_viewed&lt;/li&gt;
&lt;li&gt;story_reacted&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;A Media Cleanup Worker consumes expiration events and:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deletes media from object storage&lt;/li&gt;
&lt;li&gt;Removes CDN references&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cleanup happens asynchronously, keeping user-facing APIs fast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Engagement Tracking (Views &amp;amp; Reactions)&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;User engagement is handled by separate services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;View Tracking Service – tracks story views&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reaction Service – likes, emojis, and replies&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These services:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Handle extremely high write throughput&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Are eventually consistent&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do not impact feed read performance&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Engagement data is later aggregated for analytics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Stories systems are deceptively complex. By designing explicitly for expiration, visibility, and scale, we can build systems that are resilient, efficient, and easy to evolve.&lt;/p&gt;

&lt;p&gt;This design closely mirrors how platforms like Instagram and WhatsApp handle ephemeral content at massive scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This design is open to improvements and reviews. I’d love to hear feedback or alternative approaches.This is my first design.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>lld</category>
      <category>hld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
    </item>
  </channel>
</rss>
