How to Enable and Disable AdSense in Jekyll Minimal Mistakes Blog

34 minute read

How to Enable and Disable AdSense in Jekyll Minimal Mistakes Blog

Introduction

Google AdSense is a popular way to monetize your blog by displaying relevant advertisements to your visitors. This tutorial will guide you through implementing, enabling, and disabling AdSense in a Jekyll blog using the Minimal Mistakes theme.

Understanding the AdSense Implementation

In this Jekyll Minimal Mistakes setup, AdSense is implemented through:

  1. Advertisement HTML includes - Separate files for different ad formats
  2. Layout integration - Including ads in the blog post layout
  3. Configuration management - Optional configuration in _config.yml

File Structure for AdSense

_includes/
├── advertisements.html          # Horizontal ad unit
├── vertical_advertisement.html  # Vertical/responsive ad unit
└── adsense.html                # Basic placeholder (currently empty)

_layouts/
├── single.html                 # Main post layout where ads are included
└── default.html                # Base layout with global AdSense scripts

Important Note: AdSense code can exist in multiple locations. The default.html layout is the base template for all pages and may contain global AdSense scripts that affect the entire site.

Setting Up AdSense (Enabling)

Step 1: Create Google AdSense Account

  1. Go to Google AdSense
  2. Sign up and add your website
  3. Wait for approval
  4. Once approved, create ad units and get your publisher ID

Step 2: Create Advertisement HTML Files

Create or modify the following files in your _includes directory:

_includes/advertisements.html (Horizontal Ad)

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=YOUR-PUBLISHER-ID"
     crossorigin="anonymous"></script>
<!-- Horizontal Unit -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="YOUR-PUBLISHER-ID"
     data-ad-slot="YOUR-AD-SLOT-ID"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

_includes/vertical_advertisement.html (Responsive Ad)

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=YOUR-PUBLISHER-ID"
     crossorigin="anonymous"></script>
<!-- vertical unit -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="YOUR-PUBLISHER-ID"
     data-ad-slot="YOUR-VERTICAL-AD-SLOT-ID"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

Important: Replace YOUR-PUBLISHER-ID with your actual Google AdSense publisher ID (format: ca-pub-xxxxxxxxxx) and YOUR-AD-SLOT-ID with your specific ad unit slot IDs.

Step 3: Include Ads in Layout

Modify your _layouts/single.html file to include the advertisement files:

<!-- Include vertical ad in sidebar (around line 45) -->
<!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3654930341568980"
     crossorigin="anonymous"></script>
<!-- vertical unit -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-3654930341568980"
     data-ad-slot="2244980843"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
-->

<!-- Include horizontal ad after content (around line 50) -->




<div id="main" role="main">
  
  <div class="sidebar sticky">
  


<div itemscope itemtype="https://schema.org/Person">

  
    <div class="author__avatar">
      

      
        <img src="/assets/images/me.jpg" alt="Mahedee Hasan" itemprop="image">
      
    </div>
  

  <div class="author__content">
    
      <h3 class="author__name" itemprop="name">Mahedee Hasan</h3>
    
    
      <div class="author__bio" itemprop="description">
        <p>I am a Microsoft MVP (11th times), programmer, software developer, software architect, consultant, author, researcher, technical blogger, technical speaker, trainer and learner. I have more than 17 years experience in the field of software design and development.</p>

      </div>
    
  </div>

  <div class="author__urls-wrapper">
    <button class="btn btn--inverse">Follow</button>
    <ul class="author__urls social-icons">
      
        <li itemprop="homeLocation" itemscope itemtype="https://schema.org/Place">
          <i class="fas fa-fw fa-map-marker-alt" aria-hidden="true"></i> <span itemprop="name">Toronto, Ontario, Canada</span>
        </li>
      

      
        
          
            <li><a href="mailto:mahedee.hasan@gmail.com" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-envelope-square" aria-hidden="true"></i> Email</a></li>
          
        
          
            <li><a href="https://mahedee.net" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-link" aria-hidden="true"></i> Website</a></li>
          
        
          
            <li><a href="https://mvp.microsoft.com/en-us/PublicProfile/5001294" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-award" aria-hidden="true"></i> MVP</a></li>
          
        
          
            <li><a href="https://www.linkedin.com/in/mahedee/" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-linkedin" aria-hidden="true"></i> LinkedIn</a></li>
          
        
          
            <li><a href="https://twitter.com/mahedeehasan" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-twitter-square" aria-hidden="true"></i> Twitter</a></li>
          
        
          
            <li><a href="https://facebook.com/mahedee19" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-facebook-square" aria-hidden="true"></i> Facebook</a></li>
          
        
          
            <li><a href="https://github.com/mahedee" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-github" aria-hidden="true"></i> GitHub</a></li>
          
        
          
            <li><a href="https://www.buymeacoffee.com/mahedee" rel="nofollow noopener noreferrer"><i class="fab fa fa-coffee" aria-hidden="true"></i> Buy me a Coffee</a></li>
          
        
          
        
      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      <!--
  <li>
    <a href="http://link-to-whatever-social-network.com/user/" itemprop="sameAs" rel="nofollow noopener noreferrer">
      <i class="fas fa-fw" aria-hidden="true"></i> Custom Social Profile Link
    </a>
  </li>
-->
    </ul>
  </div>
</div>

  
  </div>


  <article class="page" itemscope itemtype="https://schema.org/CreativeWork">
    <meta itemprop="headline" content="Real-Time vs Persistent Notifications: Choosing Between Observer Pattern and Databases">
    <meta itemprop="description" content="Deciding between real-time notifications with the Observer pattern and persistent updates using databases can be challenging. This article breaks down their differences, practical use cases, and when to choose each approach to optimize your application’s performance and user experience.">
    <meta itemprop="datePublished" content="December 02, 2024">
    

    <div class="page__inner-wrap">
      
        <header>
          <h1 id="page-title" class="page__title" itemprop="headline">Real-Time vs Persistent Notifications: Choosing Between Observer Pattern and Databases
</h1>
          
            <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  3 minute read
</p>
          
        </header>
      

      <section class="page__content" itemprop="text">
        
        <p>In modern application development, delivering timely and accurate notifications is crucial to ensuring a seamless user experience. However, the mechanisms used to handle notifications can vary significantly depending on the application’s needs. Two commonly used approaches are the <strong>Observer Design Pattern</strong> for real-time notifications and <strong>databases</strong> for persistent notifications. This article delves into the differences between these methods, their practical use cases, and guidance on when to use each.</p>

<p><strong>Understanding the Basics</strong></p>

<p><strong>The Observer Pattern</strong><br />
The Observer pattern is a behavioral design pattern where an object, called the <strong>subject</strong>, maintains a list of its dependents, known as <strong>observers</strong>, and notifies them of any state changes. It is ideal for scenarios requiring <strong>real-time updates</strong>.</p>

<p><strong>Key Characteristics:</strong></p>
<ul>
  <li>Real-time notifications.</li>
  <li>Decouples subjects and observers.</li>
  <li>Flexible for dynamic subscription and unsubscription.</li>
</ul>

<p><strong>Example:</strong> Stock market applications notify registered users of price changes in real-time.</p>

<p><strong>Database-Driven Notifications</strong>
In contrast, databases are used to store notifications persistently. Applications periodically query the database or send notifications based on database triggers. This approach suits scenarios where users may not need immediate updates.</p>

<p><strong>Key Characteristics:</strong></p>
<ul>
  <li>Persistent data storage.</li>
  <li>Reliable for offline access.</li>
  <li>Better for historical data retrieval and reporting.</li>
</ul>

<p><strong>Example:</strong> Email notifications for account activity or billing reminders are generated and stored in a database before being sent to users.</p>

<p><strong>When to Use the Observer Pattern</strong></p>

<p><strong>1. Real-Time Updates</strong><br />
When users need <strong>instant notifications</strong> about events, such as:</p>
<ul>
  <li>Stock price changes.</li>
  <li>Live sports scores.</li>
  <li>Real-time chat applications.</li>
</ul>

<p><strong>Why Use Observer Pattern?</strong><br />
The Observer pattern’s ability to push updates immediately ensures users receive information without delay.</p>

<p><strong>2. Dynamic User Subscriptions</strong><br />
In scenarios where users frequently subscribe or unsubscribe to updates, such as:</p>
<ul>
  <li>News apps with customizable notifications.</li>
  <li>Weather updates for specific locations.</li>
</ul>

<p><strong>Why Use Observer Pattern?</strong><br />
The pattern dynamically manages subscriptions without requiring extensive database operations.</p>

<p><strong>3. Event-Driven Architectures</strong><br />
Applications with a high volume of <strong>events triggering actions</strong> benefit from the Observer pattern, such as:</p>
<ul>
  <li>IoT systems where sensors notify a central system of status changes.</li>
  <li>Gaming systems providing real-time alerts.</li>
</ul>

<p><strong>When to Use Databases for Notifications</strong></p>

<p><strong>1. Historical Data and Persistent Storage</strong><br />
When notifications need to be stored for later reference or analytics, such as:</p>
<ul>
  <li>Banking apps saving transaction alerts.</li>
  <li>E-commerce platforms storing order updates.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases ensure data integrity and allow users to access past notifications at any time.</p>

<p><strong>2. Offline Notifications</strong><br />
For applications where users might not always be connected, such as:</p>
<ul>
  <li>Travel apps storing booking confirmations.</li>
  <li>Educational platforms saving course notifications.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases allow notifications to persist until the user reconnects.</p>

<p><strong>3. Bulk Notifications</strong><br />
When sending notifications to a large user base, such as:</p>
<ul>
  <li>Marketing emails or SMS campaigns.</li>
  <li>System-wide announcements in corporate tools.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases can batch-process notifications and ensure delivery to all recipients without overwhelming the system.</p>

<p><strong>Combining Observer Pattern and Databases</strong></p>

<p>Many applications blend both approaches for a balanced solution. For example:</p>
<ul>
  <li>A news app uses the Observer pattern to deliver breaking news in real-time and stores all notifications in a database for users to browse later.</li>
  <li>A stock trading app pushes real-time price alerts using the Observer pattern while persisting all alerts in a database for audit purposes.</li>
</ul>

<p><strong>How It Works:</strong></p>
<ol>
  <li>The Observer pattern handles immediate delivery.</li>
  <li>A separate service persists the notifications in a database.</li>
  <li>Users can access past notifications through database queries.</li>
</ol>

<p><strong>Advantages and Limitations</strong></p>

<p><strong>Observer Pattern</strong><br />
<strong>Advantages:</strong></p>
<ul>
  <li>Provides instant updates.</li>
  <li>Decouples components for better scalability.</li>
</ul>

<p><strong>Limitations:</strong></p>
<ul>
  <li>May become complex with too many observers.</li>
  <li>No built-in persistence for notifications.</li>
</ul>

<h3 id="databases">Databases</h3>
<p><strong>Advantages:</strong></p>
<ul>
  <li>Reliable for storing and retrieving data.</li>
  <li>Ensures notifications are available even if users are offline.</li>
</ul>

<p><strong>Limitations:</strong></p>
<ul>
  <li>Cannot deliver real-time updates without additional components like polling or WebSockets.</li>
</ul>

<p><strong>Choosing the Right Approach</strong></p>

<table>
  <thead>
    <tr>
      <th><strong>Criterion</strong></th>
      <th><strong>Observer Pattern</strong></th>
      <th><strong>Database</strong></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><strong>Notification Speed</strong></td>
      <td>Real-time</td>
      <td>Slightly delayed</td>
    </tr>
    <tr>
      <td><strong>Persistence</strong></td>
      <td>Not built-in</td>
      <td>Yes</td>
    </tr>
    <tr>
      <td><strong>Offline Access</strong></td>
      <td>No</td>
      <td>Yes</td>
    </tr>
    <tr>
      <td><strong>Dynamic Subscriptions</strong></td>
      <td>Highly suitable</td>
      <td>May require additional logic</td>
    </tr>
    <tr>
      <td><strong>Use Case Examples</strong></td>
      <td>Stock alerts, live sports updates</td>
      <td>Billing reminders, historical logs</td>
    </tr>
  </tbody>
</table>

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

<p>The Observer pattern and databases serve distinct purposes in handling notifications. While the Observer pattern excels in real-time scenarios, databases provide reliability and persistence. Choosing the right approach—or combining both—depends on your application’s specific requirements. By understanding their strengths and limitations, you can design a notification system that meets both immediate and long-term needs effectively.</p>


        <!-- AdSense disabled: <!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3654930341568980"
     crossorigin="anonymous"></script>
<!-- Horizontal Unit -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-3654930341568980"
     data-ad-slot="7189599032"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
--> -->
        
      </section>

      <footer class="page__meta">
        
        
  


  
  
  

  <p class="page__taxonomy">
    <strong><i class="fas fa-fw fa-tags" aria-hidden="true"></i> Tags: </strong>
    <span itemprop="keywords">
    
      
      
      <a href="/tags/#database" class="page__taxonomy-item" rel="tag">database</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#design-pattern" class="page__taxonomy-item" rel="tag">design-pattern</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#observer-pattern" class="page__taxonomy-item" rel="tag">observer-pattern</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#software-architecture" class="page__taxonomy-item" rel="tag">software-architecture</a>
    
    </span>
  </p>




  


  
  
  

  <p class="page__taxonomy">
    <strong><i class="fas fa-fw fa-folder-open" aria-hidden="true"></i> Categories: </strong>
    <span itemprop="keywords">
    
      
      
      <a href="/categories/#database" class="page__taxonomy-item" rel="tag">Database</a><span class="sep">, </span>
    
      
      
      <a href="/categories/#design-pattern" class="page__taxonomy-item" rel="tag">Design Pattern</a><span class="sep">, </span>
    
      
      
      <a href="/categories/#software-architecture" class="page__taxonomy-item" rel="tag">Software Architecture</a>
    
    </span>
  </p>


        
          <p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> Updated:</strong> <time datetime="2024-12-02T00:00:00-05:00">December 02, 2024</time></p>
        
      </footer>

      <section class="page__share">
  

  <a href="https://twitter.com/intent/tweet?text=Real-Time+vs+Persistent+Notifications%3A+Choosing+Between+Observer+Pattern+and+Databases%20https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--twitter" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on Twitter"><i class="fab fa-fw fa-twitter" aria-hidden="true"></i><span> Twitter</span></a>

  <a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--facebook" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on Facebook"><i class="fab fa-fw fa-facebook" aria-hidden="true"></i><span> Facebook</span></a>

  <a href="https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--linkedin" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on LinkedIn"><i class="fab fa-fw fa-linkedin" aria-hidden="true"></i><span> LinkedIn</span></a>
</section>


      
  <nav class="pagination">
    
      <a href="/leveraging_the_observer_design_pattern_10_real_world_examples_in_action/" class="pagination--pager" title="Leveraging the Observer Design Pattern : 10 Real-World Examples in Action
">Previous</a>
    
    
      <a href="/how-to-enable-disable-adsense-jekyll-minimal-mistakes/" class="pagination--pager" title="How to Enable and Disable AdSense in Jekyll Minimal Mistakes Blog
">Next</a>
    
  </nav>

    </div>

    
      <div class="page__comments">
  
  
      <h4 class="page__comments-title">Comments</h4>
      <div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v18.0&appId=1641495303280571"></script>

<div class="fb-comments" 
     data-href="https://mahedee.net/real_time_vs_persistent_notifications_observer_pattern_or_databases/" 
     data-width="100%" 
     data-numposts="10"
     data-colorscheme="light"
     data-order-by="social"
     data-mobile="true">
</div>
    
</div>

    
  </article>

  
  
    <div class="page__related">
      <h4 class="page__related-title">You May Also Enjoy</h4>
      <div class="grid__wrapper">
        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/2010-01-01-could-not-access-network-location-systemdriveinetpubwwwroot/" rel="permalink">
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  2 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">
</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/procedural-vs-object-oriented-programming/" rel="permalink">Procedural vs Object-Oriented Programming: Key Differences Explained
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  6 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">A comprehensive comparison of procedural and object-oriented programming paradigms, exploring their key differences, advantages, and practical applications i...</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/implementing-metrics-and-dashboards-dotnet-core-api-prometheus-grafana/" rel="permalink">Implementing Metrics and Dashboards for .NET Core APIs with Prometheus and Grafana
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  18 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">Step-by-step tutorial to implement metrics and dashboards for .NET Core APIs using Prometheus and Grafana for effective monitoring.
</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/my-vs-code-extensions-for-daily-development/" rel="permalink">My VS Code Extensions for Daily Development Work
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  3 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">A comprehensive list of VS Code extensions I use daily for development, productivity, and coding efficiency across multiple languages and frameworks.
</p>
  </article>
</div>

        
      </div>
    </div>
  
  
</div>

<!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3654930341568980"
     crossorigin="anonymous"></script>
<!-- Horizontal Unit -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-3654930341568980"
     data-ad-slot="7189599032"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
-->

Step 4: Configure Global AdSense (Optional)

You may also add global AdSense scripts in _layouts/default.html for site-wide functionality:

<!-- In the main content area -->
<div class="initial-content">
  



<div id="main" role="main">
  
  <div class="sidebar sticky">
  


<div itemscope itemtype="https://schema.org/Person">

  
    <div class="author__avatar">
      

      
        <img src="/assets/images/me.jpg" alt="Mahedee Hasan" itemprop="image">
      
    </div>
  

  <div class="author__content">
    
      <h3 class="author__name" itemprop="name">Mahedee Hasan</h3>
    
    
      <div class="author__bio" itemprop="description">
        <p>I am a Microsoft MVP (11th times), programmer, software developer, software architect, consultant, author, researcher, technical blogger, technical speaker, trainer and learner. I have more than 17 years experience in the field of software design and development.</p>

      </div>
    
  </div>

  <div class="author__urls-wrapper">
    <button class="btn btn--inverse">Follow</button>
    <ul class="author__urls social-icons">
      
        <li itemprop="homeLocation" itemscope itemtype="https://schema.org/Place">
          <i class="fas fa-fw fa-map-marker-alt" aria-hidden="true"></i> <span itemprop="name">Toronto, Ontario, Canada</span>
        </li>
      

      
        
          
            <li><a href="mailto:mahedee.hasan@gmail.com" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-envelope-square" aria-hidden="true"></i> Email</a></li>
          
        
          
            <li><a href="https://mahedee.net" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-link" aria-hidden="true"></i> Website</a></li>
          
        
          
            <li><a href="https://mvp.microsoft.com/en-us/PublicProfile/5001294" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-award" aria-hidden="true"></i> MVP</a></li>
          
        
          
            <li><a href="https://www.linkedin.com/in/mahedee/" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-linkedin" aria-hidden="true"></i> LinkedIn</a></li>
          
        
          
            <li><a href="https://twitter.com/mahedeehasan" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-twitter-square" aria-hidden="true"></i> Twitter</a></li>
          
        
          
            <li><a href="https://facebook.com/mahedee19" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-facebook-square" aria-hidden="true"></i> Facebook</a></li>
          
        
          
            <li><a href="https://github.com/mahedee" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-github" aria-hidden="true"></i> GitHub</a></li>
          
        
          
            <li><a href="https://www.buymeacoffee.com/mahedee" rel="nofollow noopener noreferrer"><i class="fab fa fa-coffee" aria-hidden="true"></i> Buy me a Coffee</a></li>
          
        
          
        
      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      <!--
  <li>
    <a href="http://link-to-whatever-social-network.com/user/" itemprop="sameAs" rel="nofollow noopener noreferrer">
      <i class="fas fa-fw" aria-hidden="true"></i> Custom Social Profile Link
    </a>
  </li>
-->
    </ul>
  </div>
</div>

  
  </div>


  <article class="page" itemscope itemtype="https://schema.org/CreativeWork">
    <meta itemprop="headline" content="Real-Time vs Persistent Notifications: Choosing Between Observer Pattern and Databases">
    <meta itemprop="description" content="Deciding between real-time notifications with the Observer pattern and persistent updates using databases can be challenging. This article breaks down their differences, practical use cases, and when to choose each approach to optimize your application’s performance and user experience.">
    <meta itemprop="datePublished" content="December 02, 2024">
    

    <div class="page__inner-wrap">
      
        <header>
          <h1 id="page-title" class="page__title" itemprop="headline">Real-Time vs Persistent Notifications: Choosing Between Observer Pattern and Databases
</h1>
          
            <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  3 minute read
</p>
          
        </header>
      

      <section class="page__content" itemprop="text">
        
        <p>In modern application development, delivering timely and accurate notifications is crucial to ensuring a seamless user experience. However, the mechanisms used to handle notifications can vary significantly depending on the application’s needs. Two commonly used approaches are the <strong>Observer Design Pattern</strong> for real-time notifications and <strong>databases</strong> for persistent notifications. This article delves into the differences between these methods, their practical use cases, and guidance on when to use each.</p>

<p><strong>Understanding the Basics</strong></p>

<p><strong>The Observer Pattern</strong><br />
The Observer pattern is a behavioral design pattern where an object, called the <strong>subject</strong>, maintains a list of its dependents, known as <strong>observers</strong>, and notifies them of any state changes. It is ideal for scenarios requiring <strong>real-time updates</strong>.</p>

<p><strong>Key Characteristics:</strong></p>
<ul>
  <li>Real-time notifications.</li>
  <li>Decouples subjects and observers.</li>
  <li>Flexible for dynamic subscription and unsubscription.</li>
</ul>

<p><strong>Example:</strong> Stock market applications notify registered users of price changes in real-time.</p>

<p><strong>Database-Driven Notifications</strong>
In contrast, databases are used to store notifications persistently. Applications periodically query the database or send notifications based on database triggers. This approach suits scenarios where users may not need immediate updates.</p>

<p><strong>Key Characteristics:</strong></p>
<ul>
  <li>Persistent data storage.</li>
  <li>Reliable for offline access.</li>
  <li>Better for historical data retrieval and reporting.</li>
</ul>

<p><strong>Example:</strong> Email notifications for account activity or billing reminders are generated and stored in a database before being sent to users.</p>

<p><strong>When to Use the Observer Pattern</strong></p>

<p><strong>1. Real-Time Updates</strong><br />
When users need <strong>instant notifications</strong> about events, such as:</p>
<ul>
  <li>Stock price changes.</li>
  <li>Live sports scores.</li>
  <li>Real-time chat applications.</li>
</ul>

<p><strong>Why Use Observer Pattern?</strong><br />
The Observer pattern’s ability to push updates immediately ensures users receive information without delay.</p>

<p><strong>2. Dynamic User Subscriptions</strong><br />
In scenarios where users frequently subscribe or unsubscribe to updates, such as:</p>
<ul>
  <li>News apps with customizable notifications.</li>
  <li>Weather updates for specific locations.</li>
</ul>

<p><strong>Why Use Observer Pattern?</strong><br />
The pattern dynamically manages subscriptions without requiring extensive database operations.</p>

<p><strong>3. Event-Driven Architectures</strong><br />
Applications with a high volume of <strong>events triggering actions</strong> benefit from the Observer pattern, such as:</p>
<ul>
  <li>IoT systems where sensors notify a central system of status changes.</li>
  <li>Gaming systems providing real-time alerts.</li>
</ul>

<p><strong>When to Use Databases for Notifications</strong></p>

<p><strong>1. Historical Data and Persistent Storage</strong><br />
When notifications need to be stored for later reference or analytics, such as:</p>
<ul>
  <li>Banking apps saving transaction alerts.</li>
  <li>E-commerce platforms storing order updates.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases ensure data integrity and allow users to access past notifications at any time.</p>

<p><strong>2. Offline Notifications</strong><br />
For applications where users might not always be connected, such as:</p>
<ul>
  <li>Travel apps storing booking confirmations.</li>
  <li>Educational platforms saving course notifications.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases allow notifications to persist until the user reconnects.</p>

<p><strong>3. Bulk Notifications</strong><br />
When sending notifications to a large user base, such as:</p>
<ul>
  <li>Marketing emails or SMS campaigns.</li>
  <li>System-wide announcements in corporate tools.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases can batch-process notifications and ensure delivery to all recipients without overwhelming the system.</p>

<p><strong>Combining Observer Pattern and Databases</strong></p>

<p>Many applications blend both approaches for a balanced solution. For example:</p>
<ul>
  <li>A news app uses the Observer pattern to deliver breaking news in real-time and stores all notifications in a database for users to browse later.</li>
  <li>A stock trading app pushes real-time price alerts using the Observer pattern while persisting all alerts in a database for audit purposes.</li>
</ul>

<p><strong>How It Works:</strong></p>
<ol>
  <li>The Observer pattern handles immediate delivery.</li>
  <li>A separate service persists the notifications in a database.</li>
  <li>Users can access past notifications through database queries.</li>
</ol>

<p><strong>Advantages and Limitations</strong></p>

<p><strong>Observer Pattern</strong><br />
<strong>Advantages:</strong></p>
<ul>
  <li>Provides instant updates.</li>
  <li>Decouples components for better scalability.</li>
</ul>

<p><strong>Limitations:</strong></p>
<ul>
  <li>May become complex with too many observers.</li>
  <li>No built-in persistence for notifications.</li>
</ul>

<h3 id="databases">Databases</h3>
<p><strong>Advantages:</strong></p>
<ul>
  <li>Reliable for storing and retrieving data.</li>
  <li>Ensures notifications are available even if users are offline.</li>
</ul>

<p><strong>Limitations:</strong></p>
<ul>
  <li>Cannot deliver real-time updates without additional components like polling or WebSockets.</li>
</ul>

<p><strong>Choosing the Right Approach</strong></p>

<table>
  <thead>
    <tr>
      <th><strong>Criterion</strong></th>
      <th><strong>Observer Pattern</strong></th>
      <th><strong>Database</strong></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><strong>Notification Speed</strong></td>
      <td>Real-time</td>
      <td>Slightly delayed</td>
    </tr>
    <tr>
      <td><strong>Persistence</strong></td>
      <td>Not built-in</td>
      <td>Yes</td>
    </tr>
    <tr>
      <td><strong>Offline Access</strong></td>
      <td>No</td>
      <td>Yes</td>
    </tr>
    <tr>
      <td><strong>Dynamic Subscriptions</strong></td>
      <td>Highly suitable</td>
      <td>May require additional logic</td>
    </tr>
    <tr>
      <td><strong>Use Case Examples</strong></td>
      <td>Stock alerts, live sports updates</td>
      <td>Billing reminders, historical logs</td>
    </tr>
  </tbody>
</table>

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

<p>The Observer pattern and databases serve distinct purposes in handling notifications. While the Observer pattern excels in real-time scenarios, databases provide reliability and persistence. Choosing the right approach—or combining both—depends on your application’s specific requirements. By understanding their strengths and limitations, you can design a notification system that meets both immediate and long-term needs effectively.</p>


        <!-- AdSense disabled: <!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3654930341568980"
     crossorigin="anonymous"></script>
<!-- Horizontal Unit -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-3654930341568980"
     data-ad-slot="7189599032"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
--> -->
        
      </section>

      <footer class="page__meta">
        
        
  


  
  
  

  <p class="page__taxonomy">
    <strong><i class="fas fa-fw fa-tags" aria-hidden="true"></i> Tags: </strong>
    <span itemprop="keywords">
    
      
      
      <a href="/tags/#database" class="page__taxonomy-item" rel="tag">database</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#design-pattern" class="page__taxonomy-item" rel="tag">design-pattern</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#observer-pattern" class="page__taxonomy-item" rel="tag">observer-pattern</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#software-architecture" class="page__taxonomy-item" rel="tag">software-architecture</a>
    
    </span>
  </p>




  


  
  
  

  <p class="page__taxonomy">
    <strong><i class="fas fa-fw fa-folder-open" aria-hidden="true"></i> Categories: </strong>
    <span itemprop="keywords">
    
      
      
      <a href="/categories/#database" class="page__taxonomy-item" rel="tag">Database</a><span class="sep">, </span>
    
      
      
      <a href="/categories/#design-pattern" class="page__taxonomy-item" rel="tag">Design Pattern</a><span class="sep">, </span>
    
      
      
      <a href="/categories/#software-architecture" class="page__taxonomy-item" rel="tag">Software Architecture</a>
    
    </span>
  </p>


        
          <p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> Updated:</strong> <time datetime="2024-12-02T00:00:00-05:00">December 02, 2024</time></p>
        
      </footer>

      <section class="page__share">
  

  <a href="https://twitter.com/intent/tweet?text=Real-Time+vs+Persistent+Notifications%3A+Choosing+Between+Observer+Pattern+and+Databases%20https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--twitter" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on Twitter"><i class="fab fa-fw fa-twitter" aria-hidden="true"></i><span> Twitter</span></a>

  <a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--facebook" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on Facebook"><i class="fab fa-fw fa-facebook" aria-hidden="true"></i><span> Facebook</span></a>

  <a href="https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--linkedin" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on LinkedIn"><i class="fab fa-fw fa-linkedin" aria-hidden="true"></i><span> LinkedIn</span></a>
</section>


      
  <nav class="pagination">
    
      <a href="/leveraging_the_observer_design_pattern_10_real_world_examples_in_action/" class="pagination--pager" title="Leveraging the Observer Design Pattern : 10 Real-World Examples in Action
">Previous</a>
    
    
      <a href="/how-to-enable-disable-adsense-jekyll-minimal-mistakes/" class="pagination--pager" title="How to Enable and Disable AdSense in Jekyll Minimal Mistakes Blog
">Next</a>
    
  </nav>

    </div>

    
      <div class="page__comments">
  
  
      <h4 class="page__comments-title">Comments</h4>
      <div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v18.0&appId=1641495303280571"></script>

<div class="fb-comments" 
     data-href="https://mahedee.net/real_time_vs_persistent_notifications_observer_pattern_or_databases/" 
     data-width="100%" 
     data-numposts="10"
     data-colorscheme="light"
     data-order-by="social"
     data-mobile="true">
</div>
    
</div>

    
  </article>

  
  
    <div class="page__related">
      <h4 class="page__related-title">You May Also Enjoy</h4>
      <div class="grid__wrapper">
        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/2010-01-01-could-not-access-network-location-systemdriveinetpubwwwroot/" rel="permalink">
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  2 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">
</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/procedural-vs-object-oriented-programming/" rel="permalink">Procedural vs Object-Oriented Programming: Key Differences Explained
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  6 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">A comprehensive comparison of procedural and object-oriented programming paradigms, exploring their key differences, advantages, and practical applications i...</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/implementing-metrics-and-dashboards-dotnet-core-api-prometheus-grafana/" rel="permalink">Implementing Metrics and Dashboards for .NET Core APIs with Prometheus and Grafana
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  18 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">Step-by-step tutorial to implement metrics and dashboards for .NET Core APIs using Prometheus and Grafana for effective monitoring.
</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/my-vs-code-extensions-for-daily-development/" rel="permalink">My VS Code Extensions for Daily Development Work
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  3 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">A comprehensive list of VS Code extensions I use daily for development, productivity, and coding efficiency across multiple languages and frameworks.
</p>
  </article>
</div>

        
      </div>
    </div>
  
  
</div>

  
  <ins class="adsbygoogle"
       style="display:block"
       data-ad-client="YOUR-PUBLISHER-ID"
       data-ad-slot="YOUR-AD-SLOT-ID"
       data-ad-format="auto"
       data-full-width-responsive="true"></ins>
</div>

<!-- Before closing body tag -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=YOUR-PUBLISHER-ID"
        crossorigin="anonymous"></script>

Create or update the ads.txt file in your root directory:

google.com, pub-YOUR-PUBLISHER-ID, DIRECT, f08c47fec0942fa0

Replace YOUR-PUBLISHER-ID with your actual publisher ID.

Disabling AdSense

There are several ways to disable AdSense depending on your needs. Important: You must check ALL locations where AdSense code might exist.

This comprehensive method ensures all AdSense code is disabled:

Step 1: Comment out ad includes in _layouts/single.html:

<!-- AdSense disabled: <!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3654930341568980"
     crossorigin="anonymous"></script>
<!-- vertical unit -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-3654930341568980"
     data-ad-slot="2244980843"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
--> -->





<div id="main" role="main">
  
  <div class="sidebar sticky">
  


<div itemscope itemtype="https://schema.org/Person">

  
    <div class="author__avatar">
      

      
        <img src="/assets/images/me.jpg" alt="Mahedee Hasan" itemprop="image">
      
    </div>
  

  <div class="author__content">
    
      <h3 class="author__name" itemprop="name">Mahedee Hasan</h3>
    
    
      <div class="author__bio" itemprop="description">
        <p>I am a Microsoft MVP (11th times), programmer, software developer, software architect, consultant, author, researcher, technical blogger, technical speaker, trainer and learner. I have more than 17 years experience in the field of software design and development.</p>

      </div>
    
  </div>

  <div class="author__urls-wrapper">
    <button class="btn btn--inverse">Follow</button>
    <ul class="author__urls social-icons">
      
        <li itemprop="homeLocation" itemscope itemtype="https://schema.org/Place">
          <i class="fas fa-fw fa-map-marker-alt" aria-hidden="true"></i> <span itemprop="name">Toronto, Ontario, Canada</span>
        </li>
      

      
        
          
            <li><a href="mailto:mahedee.hasan@gmail.com" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-envelope-square" aria-hidden="true"></i> Email</a></li>
          
        
          
            <li><a href="https://mahedee.net" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-link" aria-hidden="true"></i> Website</a></li>
          
        
          
            <li><a href="https://mvp.microsoft.com/en-us/PublicProfile/5001294" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-award" aria-hidden="true"></i> MVP</a></li>
          
        
          
            <li><a href="https://www.linkedin.com/in/mahedee/" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-linkedin" aria-hidden="true"></i> LinkedIn</a></li>
          
        
          
            <li><a href="https://twitter.com/mahedeehasan" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-twitter-square" aria-hidden="true"></i> Twitter</a></li>
          
        
          
            <li><a href="https://facebook.com/mahedee19" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-facebook-square" aria-hidden="true"></i> Facebook</a></li>
          
        
          
            <li><a href="https://github.com/mahedee" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-github" aria-hidden="true"></i> GitHub</a></li>
          
        
          
            <li><a href="https://www.buymeacoffee.com/mahedee" rel="nofollow noopener noreferrer"><i class="fab fa fa-coffee" aria-hidden="true"></i> Buy me a Coffee</a></li>
          
        
          
        
      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      <!--
  <li>
    <a href="http://link-to-whatever-social-network.com/user/" itemprop="sameAs" rel="nofollow noopener noreferrer">
      <i class="fas fa-fw" aria-hidden="true"></i> Custom Social Profile Link
    </a>
  </li>
-->
    </ul>
  </div>
</div>

  
  </div>


  <article class="page" itemscope itemtype="https://schema.org/CreativeWork">
    <meta itemprop="headline" content="Real-Time vs Persistent Notifications: Choosing Between Observer Pattern and Databases">
    <meta itemprop="description" content="Deciding between real-time notifications with the Observer pattern and persistent updates using databases can be challenging. This article breaks down their differences, practical use cases, and when to choose each approach to optimize your application’s performance and user experience.">
    <meta itemprop="datePublished" content="December 02, 2024">
    

    <div class="page__inner-wrap">
      
        <header>
          <h1 id="page-title" class="page__title" itemprop="headline">Real-Time vs Persistent Notifications: Choosing Between Observer Pattern and Databases
</h1>
          
            <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  3 minute read
</p>
          
        </header>
      

      <section class="page__content" itemprop="text">
        
        <p>In modern application development, delivering timely and accurate notifications is crucial to ensuring a seamless user experience. However, the mechanisms used to handle notifications can vary significantly depending on the application’s needs. Two commonly used approaches are the <strong>Observer Design Pattern</strong> for real-time notifications and <strong>databases</strong> for persistent notifications. This article delves into the differences between these methods, their practical use cases, and guidance on when to use each.</p>

<p><strong>Understanding the Basics</strong></p>

<p><strong>The Observer Pattern</strong><br />
The Observer pattern is a behavioral design pattern where an object, called the <strong>subject</strong>, maintains a list of its dependents, known as <strong>observers</strong>, and notifies them of any state changes. It is ideal for scenarios requiring <strong>real-time updates</strong>.</p>

<p><strong>Key Characteristics:</strong></p>
<ul>
  <li>Real-time notifications.</li>
  <li>Decouples subjects and observers.</li>
  <li>Flexible for dynamic subscription and unsubscription.</li>
</ul>

<p><strong>Example:</strong> Stock market applications notify registered users of price changes in real-time.</p>

<p><strong>Database-Driven Notifications</strong>
In contrast, databases are used to store notifications persistently. Applications periodically query the database or send notifications based on database triggers. This approach suits scenarios where users may not need immediate updates.</p>

<p><strong>Key Characteristics:</strong></p>
<ul>
  <li>Persistent data storage.</li>
  <li>Reliable for offline access.</li>
  <li>Better for historical data retrieval and reporting.</li>
</ul>

<p><strong>Example:</strong> Email notifications for account activity or billing reminders are generated and stored in a database before being sent to users.</p>

<p><strong>When to Use the Observer Pattern</strong></p>

<p><strong>1. Real-Time Updates</strong><br />
When users need <strong>instant notifications</strong> about events, such as:</p>
<ul>
  <li>Stock price changes.</li>
  <li>Live sports scores.</li>
  <li>Real-time chat applications.</li>
</ul>

<p><strong>Why Use Observer Pattern?</strong><br />
The Observer pattern’s ability to push updates immediately ensures users receive information without delay.</p>

<p><strong>2. Dynamic User Subscriptions</strong><br />
In scenarios where users frequently subscribe or unsubscribe to updates, such as:</p>
<ul>
  <li>News apps with customizable notifications.</li>
  <li>Weather updates for specific locations.</li>
</ul>

<p><strong>Why Use Observer Pattern?</strong><br />
The pattern dynamically manages subscriptions without requiring extensive database operations.</p>

<p><strong>3. Event-Driven Architectures</strong><br />
Applications with a high volume of <strong>events triggering actions</strong> benefit from the Observer pattern, such as:</p>
<ul>
  <li>IoT systems where sensors notify a central system of status changes.</li>
  <li>Gaming systems providing real-time alerts.</li>
</ul>

<p><strong>When to Use Databases for Notifications</strong></p>

<p><strong>1. Historical Data and Persistent Storage</strong><br />
When notifications need to be stored for later reference or analytics, such as:</p>
<ul>
  <li>Banking apps saving transaction alerts.</li>
  <li>E-commerce platforms storing order updates.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases ensure data integrity and allow users to access past notifications at any time.</p>

<p><strong>2. Offline Notifications</strong><br />
For applications where users might not always be connected, such as:</p>
<ul>
  <li>Travel apps storing booking confirmations.</li>
  <li>Educational platforms saving course notifications.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases allow notifications to persist until the user reconnects.</p>

<p><strong>3. Bulk Notifications</strong><br />
When sending notifications to a large user base, such as:</p>
<ul>
  <li>Marketing emails or SMS campaigns.</li>
  <li>System-wide announcements in corporate tools.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases can batch-process notifications and ensure delivery to all recipients without overwhelming the system.</p>

<p><strong>Combining Observer Pattern and Databases</strong></p>

<p>Many applications blend both approaches for a balanced solution. For example:</p>
<ul>
  <li>A news app uses the Observer pattern to deliver breaking news in real-time and stores all notifications in a database for users to browse later.</li>
  <li>A stock trading app pushes real-time price alerts using the Observer pattern while persisting all alerts in a database for audit purposes.</li>
</ul>

<p><strong>How It Works:</strong></p>
<ol>
  <li>The Observer pattern handles immediate delivery.</li>
  <li>A separate service persists the notifications in a database.</li>
  <li>Users can access past notifications through database queries.</li>
</ol>

<p><strong>Advantages and Limitations</strong></p>

<p><strong>Observer Pattern</strong><br />
<strong>Advantages:</strong></p>
<ul>
  <li>Provides instant updates.</li>
  <li>Decouples components for better scalability.</li>
</ul>

<p><strong>Limitations:</strong></p>
<ul>
  <li>May become complex with too many observers.</li>
  <li>No built-in persistence for notifications.</li>
</ul>

<h3 id="databases">Databases</h3>
<p><strong>Advantages:</strong></p>
<ul>
  <li>Reliable for storing and retrieving data.</li>
  <li>Ensures notifications are available even if users are offline.</li>
</ul>

<p><strong>Limitations:</strong></p>
<ul>
  <li>Cannot deliver real-time updates without additional components like polling or WebSockets.</li>
</ul>

<p><strong>Choosing the Right Approach</strong></p>

<table>
  <thead>
    <tr>
      <th><strong>Criterion</strong></th>
      <th><strong>Observer Pattern</strong></th>
      <th><strong>Database</strong></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><strong>Notification Speed</strong></td>
      <td>Real-time</td>
      <td>Slightly delayed</td>
    </tr>
    <tr>
      <td><strong>Persistence</strong></td>
      <td>Not built-in</td>
      <td>Yes</td>
    </tr>
    <tr>
      <td><strong>Offline Access</strong></td>
      <td>No</td>
      <td>Yes</td>
    </tr>
    <tr>
      <td><strong>Dynamic Subscriptions</strong></td>
      <td>Highly suitable</td>
      <td>May require additional logic</td>
    </tr>
    <tr>
      <td><strong>Use Case Examples</strong></td>
      <td>Stock alerts, live sports updates</td>
      <td>Billing reminders, historical logs</td>
    </tr>
  </tbody>
</table>

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

<p>The Observer pattern and databases serve distinct purposes in handling notifications. While the Observer pattern excels in real-time scenarios, databases provide reliability and persistence. Choosing the right approach—or combining both—depends on your application’s specific requirements. By understanding their strengths and limitations, you can design a notification system that meets both immediate and long-term needs effectively.</p>


        <!-- AdSense disabled: <!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3654930341568980"
     crossorigin="anonymous"></script>
<!-- Horizontal Unit -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-3654930341568980"
     data-ad-slot="7189599032"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
--> -->
        
      </section>

      <footer class="page__meta">
        
        
  


  
  
  

  <p class="page__taxonomy">
    <strong><i class="fas fa-fw fa-tags" aria-hidden="true"></i> Tags: </strong>
    <span itemprop="keywords">
    
      
      
      <a href="/tags/#database" class="page__taxonomy-item" rel="tag">database</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#design-pattern" class="page__taxonomy-item" rel="tag">design-pattern</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#observer-pattern" class="page__taxonomy-item" rel="tag">observer-pattern</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#software-architecture" class="page__taxonomy-item" rel="tag">software-architecture</a>
    
    </span>
  </p>




  


  
  
  

  <p class="page__taxonomy">
    <strong><i class="fas fa-fw fa-folder-open" aria-hidden="true"></i> Categories: </strong>
    <span itemprop="keywords">
    
      
      
      <a href="/categories/#database" class="page__taxonomy-item" rel="tag">Database</a><span class="sep">, </span>
    
      
      
      <a href="/categories/#design-pattern" class="page__taxonomy-item" rel="tag">Design Pattern</a><span class="sep">, </span>
    
      
      
      <a href="/categories/#software-architecture" class="page__taxonomy-item" rel="tag">Software Architecture</a>
    
    </span>
  </p>


        
          <p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> Updated:</strong> <time datetime="2024-12-02T00:00:00-05:00">December 02, 2024</time></p>
        
      </footer>

      <section class="page__share">
  

  <a href="https://twitter.com/intent/tweet?text=Real-Time+vs+Persistent+Notifications%3A+Choosing+Between+Observer+Pattern+and+Databases%20https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--twitter" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on Twitter"><i class="fab fa-fw fa-twitter" aria-hidden="true"></i><span> Twitter</span></a>

  <a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--facebook" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on Facebook"><i class="fab fa-fw fa-facebook" aria-hidden="true"></i><span> Facebook</span></a>

  <a href="https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--linkedin" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on LinkedIn"><i class="fab fa-fw fa-linkedin" aria-hidden="true"></i><span> LinkedIn</span></a>
</section>


      
  <nav class="pagination">
    
      <a href="/leveraging_the_observer_design_pattern_10_real_world_examples_in_action/" class="pagination--pager" title="Leveraging the Observer Design Pattern : 10 Real-World Examples in Action
">Previous</a>
    
    
      <a href="/how-to-enable-disable-adsense-jekyll-minimal-mistakes/" class="pagination--pager" title="How to Enable and Disable AdSense in Jekyll Minimal Mistakes Blog
">Next</a>
    
  </nav>

    </div>

    
      <div class="page__comments">
  
  
      <h4 class="page__comments-title">Comments</h4>
      <div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v18.0&appId=1641495303280571"></script>

<div class="fb-comments" 
     data-href="https://mahedee.net/real_time_vs_persistent_notifications_observer_pattern_or_databases/" 
     data-width="100%" 
     data-numposts="10"
     data-colorscheme="light"
     data-order-by="social"
     data-mobile="true">
</div>
    
</div>

    
  </article>

  
  
    <div class="page__related">
      <h4 class="page__related-title">You May Also Enjoy</h4>
      <div class="grid__wrapper">
        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/2010-01-01-could-not-access-network-location-systemdriveinetpubwwwroot/" rel="permalink">
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  2 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">
</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/procedural-vs-object-oriented-programming/" rel="permalink">Procedural vs Object-Oriented Programming: Key Differences Explained
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  6 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">A comprehensive comparison of procedural and object-oriented programming paradigms, exploring their key differences, advantages, and practical applications i...</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/implementing-metrics-and-dashboards-dotnet-core-api-prometheus-grafana/" rel="permalink">Implementing Metrics and Dashboards for .NET Core APIs with Prometheus and Grafana
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  18 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">Step-by-step tutorial to implement metrics and dashboards for .NET Core APIs using Prometheus and Grafana for effective monitoring.
</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/my-vs-code-extensions-for-daily-development/" rel="permalink">My VS Code Extensions for Daily Development Work
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  3 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">A comprehensive list of VS Code extensions I use daily for development, productivity, and coding efficiency across multiple languages and frameworks.
</p>
  </article>
</div>

        
      </div>
    </div>
  
  
</div>

<!-- AdSense disabled: <!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3654930341568980"
     crossorigin="anonymous"></script>
<!-- Horizontal Unit -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-3654930341568980"
     data-ad-slot="7189599032"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
--> -->

Step 2: Comment out global AdSense in _layouts/default.html:

<!-- Main content area -->
<div class="initial-content">
  



<div id="main" role="main">
  
  <div class="sidebar sticky">
  


<div itemscope itemtype="https://schema.org/Person">

  
    <div class="author__avatar">
      

      
        <img src="/assets/images/me.jpg" alt="Mahedee Hasan" itemprop="image">
      
    </div>
  

  <div class="author__content">
    
      <h3 class="author__name" itemprop="name">Mahedee Hasan</h3>
    
    
      <div class="author__bio" itemprop="description">
        <p>I am a Microsoft MVP (11th times), programmer, software developer, software architect, consultant, author, researcher, technical blogger, technical speaker, trainer and learner. I have more than 17 years experience in the field of software design and development.</p>

      </div>
    
  </div>

  <div class="author__urls-wrapper">
    <button class="btn btn--inverse">Follow</button>
    <ul class="author__urls social-icons">
      
        <li itemprop="homeLocation" itemscope itemtype="https://schema.org/Place">
          <i class="fas fa-fw fa-map-marker-alt" aria-hidden="true"></i> <span itemprop="name">Toronto, Ontario, Canada</span>
        </li>
      

      
        
          
            <li><a href="mailto:mahedee.hasan@gmail.com" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-envelope-square" aria-hidden="true"></i> Email</a></li>
          
        
          
            <li><a href="https://mahedee.net" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-link" aria-hidden="true"></i> Website</a></li>
          
        
          
            <li><a href="https://mvp.microsoft.com/en-us/PublicProfile/5001294" rel="nofollow noopener noreferrer"><i class="fas fa-fw fa-award" aria-hidden="true"></i> MVP</a></li>
          
        
          
            <li><a href="https://www.linkedin.com/in/mahedee/" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-linkedin" aria-hidden="true"></i> LinkedIn</a></li>
          
        
          
            <li><a href="https://twitter.com/mahedeehasan" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-twitter-square" aria-hidden="true"></i> Twitter</a></li>
          
        
          
            <li><a href="https://facebook.com/mahedee19" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-facebook-square" aria-hidden="true"></i> Facebook</a></li>
          
        
          
            <li><a href="https://github.com/mahedee" rel="nofollow noopener noreferrer"><i class="fab fa-fw fa-github" aria-hidden="true"></i> GitHub</a></li>
          
        
          
            <li><a href="https://www.buymeacoffee.com/mahedee" rel="nofollow noopener noreferrer"><i class="fab fa fa-coffee" aria-hidden="true"></i> Buy me a Coffee</a></li>
          
        
          
        
      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      

      <!--
  <li>
    <a href="http://link-to-whatever-social-network.com/user/" itemprop="sameAs" rel="nofollow noopener noreferrer">
      <i class="fas fa-fw" aria-hidden="true"></i> Custom Social Profile Link
    </a>
  </li>
-->
    </ul>
  </div>
</div>

  
  </div>


  <article class="page" itemscope itemtype="https://schema.org/CreativeWork">
    <meta itemprop="headline" content="Real-Time vs Persistent Notifications: Choosing Between Observer Pattern and Databases">
    <meta itemprop="description" content="Deciding between real-time notifications with the Observer pattern and persistent updates using databases can be challenging. This article breaks down their differences, practical use cases, and when to choose each approach to optimize your application’s performance and user experience.">
    <meta itemprop="datePublished" content="December 02, 2024">
    

    <div class="page__inner-wrap">
      
        <header>
          <h1 id="page-title" class="page__title" itemprop="headline">Real-Time vs Persistent Notifications: Choosing Between Observer Pattern and Databases
</h1>
          
            <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  3 minute read
</p>
          
        </header>
      

      <section class="page__content" itemprop="text">
        
        <p>In modern application development, delivering timely and accurate notifications is crucial to ensuring a seamless user experience. However, the mechanisms used to handle notifications can vary significantly depending on the application’s needs. Two commonly used approaches are the <strong>Observer Design Pattern</strong> for real-time notifications and <strong>databases</strong> for persistent notifications. This article delves into the differences between these methods, their practical use cases, and guidance on when to use each.</p>

<p><strong>Understanding the Basics</strong></p>

<p><strong>The Observer Pattern</strong><br />
The Observer pattern is a behavioral design pattern where an object, called the <strong>subject</strong>, maintains a list of its dependents, known as <strong>observers</strong>, and notifies them of any state changes. It is ideal for scenarios requiring <strong>real-time updates</strong>.</p>

<p><strong>Key Characteristics:</strong></p>
<ul>
  <li>Real-time notifications.</li>
  <li>Decouples subjects and observers.</li>
  <li>Flexible for dynamic subscription and unsubscription.</li>
</ul>

<p><strong>Example:</strong> Stock market applications notify registered users of price changes in real-time.</p>

<p><strong>Database-Driven Notifications</strong>
In contrast, databases are used to store notifications persistently. Applications periodically query the database or send notifications based on database triggers. This approach suits scenarios where users may not need immediate updates.</p>

<p><strong>Key Characteristics:</strong></p>
<ul>
  <li>Persistent data storage.</li>
  <li>Reliable for offline access.</li>
  <li>Better for historical data retrieval and reporting.</li>
</ul>

<p><strong>Example:</strong> Email notifications for account activity or billing reminders are generated and stored in a database before being sent to users.</p>

<p><strong>When to Use the Observer Pattern</strong></p>

<p><strong>1. Real-Time Updates</strong><br />
When users need <strong>instant notifications</strong> about events, such as:</p>
<ul>
  <li>Stock price changes.</li>
  <li>Live sports scores.</li>
  <li>Real-time chat applications.</li>
</ul>

<p><strong>Why Use Observer Pattern?</strong><br />
The Observer pattern’s ability to push updates immediately ensures users receive information without delay.</p>

<p><strong>2. Dynamic User Subscriptions</strong><br />
In scenarios where users frequently subscribe or unsubscribe to updates, such as:</p>
<ul>
  <li>News apps with customizable notifications.</li>
  <li>Weather updates for specific locations.</li>
</ul>

<p><strong>Why Use Observer Pattern?</strong><br />
The pattern dynamically manages subscriptions without requiring extensive database operations.</p>

<p><strong>3. Event-Driven Architectures</strong><br />
Applications with a high volume of <strong>events triggering actions</strong> benefit from the Observer pattern, such as:</p>
<ul>
  <li>IoT systems where sensors notify a central system of status changes.</li>
  <li>Gaming systems providing real-time alerts.</li>
</ul>

<p><strong>When to Use Databases for Notifications</strong></p>

<p><strong>1. Historical Data and Persistent Storage</strong><br />
When notifications need to be stored for later reference or analytics, such as:</p>
<ul>
  <li>Banking apps saving transaction alerts.</li>
  <li>E-commerce platforms storing order updates.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases ensure data integrity and allow users to access past notifications at any time.</p>

<p><strong>2. Offline Notifications</strong><br />
For applications where users might not always be connected, such as:</p>
<ul>
  <li>Travel apps storing booking confirmations.</li>
  <li>Educational platforms saving course notifications.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases allow notifications to persist until the user reconnects.</p>

<p><strong>3. Bulk Notifications</strong><br />
When sending notifications to a large user base, such as:</p>
<ul>
  <li>Marketing emails or SMS campaigns.</li>
  <li>System-wide announcements in corporate tools.</li>
</ul>

<p><strong>Why Use Databases?</strong><br />
Databases can batch-process notifications and ensure delivery to all recipients without overwhelming the system.</p>

<p><strong>Combining Observer Pattern and Databases</strong></p>

<p>Many applications blend both approaches for a balanced solution. For example:</p>
<ul>
  <li>A news app uses the Observer pattern to deliver breaking news in real-time and stores all notifications in a database for users to browse later.</li>
  <li>A stock trading app pushes real-time price alerts using the Observer pattern while persisting all alerts in a database for audit purposes.</li>
</ul>

<p><strong>How It Works:</strong></p>
<ol>
  <li>The Observer pattern handles immediate delivery.</li>
  <li>A separate service persists the notifications in a database.</li>
  <li>Users can access past notifications through database queries.</li>
</ol>

<p><strong>Advantages and Limitations</strong></p>

<p><strong>Observer Pattern</strong><br />
<strong>Advantages:</strong></p>
<ul>
  <li>Provides instant updates.</li>
  <li>Decouples components for better scalability.</li>
</ul>

<p><strong>Limitations:</strong></p>
<ul>
  <li>May become complex with too many observers.</li>
  <li>No built-in persistence for notifications.</li>
</ul>

<h3 id="databases">Databases</h3>
<p><strong>Advantages:</strong></p>
<ul>
  <li>Reliable for storing and retrieving data.</li>
  <li>Ensures notifications are available even if users are offline.</li>
</ul>

<p><strong>Limitations:</strong></p>
<ul>
  <li>Cannot deliver real-time updates without additional components like polling or WebSockets.</li>
</ul>

<p><strong>Choosing the Right Approach</strong></p>

<table>
  <thead>
    <tr>
      <th><strong>Criterion</strong></th>
      <th><strong>Observer Pattern</strong></th>
      <th><strong>Database</strong></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><strong>Notification Speed</strong></td>
      <td>Real-time</td>
      <td>Slightly delayed</td>
    </tr>
    <tr>
      <td><strong>Persistence</strong></td>
      <td>Not built-in</td>
      <td>Yes</td>
    </tr>
    <tr>
      <td><strong>Offline Access</strong></td>
      <td>No</td>
      <td>Yes</td>
    </tr>
    <tr>
      <td><strong>Dynamic Subscriptions</strong></td>
      <td>Highly suitable</td>
      <td>May require additional logic</td>
    </tr>
    <tr>
      <td><strong>Use Case Examples</strong></td>
      <td>Stock alerts, live sports updates</td>
      <td>Billing reminders, historical logs</td>
    </tr>
  </tbody>
</table>

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

<p>The Observer pattern and databases serve distinct purposes in handling notifications. While the Observer pattern excels in real-time scenarios, databases provide reliability and persistence. Choosing the right approach—or combining both—depends on your application’s specific requirements. By understanding their strengths and limitations, you can design a notification system that meets both immediate and long-term needs effectively.</p>


        <!-- AdSense disabled: <!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3654930341568980"
     crossorigin="anonymous"></script>
<!-- Horizontal Unit -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-3654930341568980"
     data-ad-slot="7189599032"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
--> -->
        
      </section>

      <footer class="page__meta">
        
        
  


  
  
  

  <p class="page__taxonomy">
    <strong><i class="fas fa-fw fa-tags" aria-hidden="true"></i> Tags: </strong>
    <span itemprop="keywords">
    
      
      
      <a href="/tags/#database" class="page__taxonomy-item" rel="tag">database</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#design-pattern" class="page__taxonomy-item" rel="tag">design-pattern</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#observer-pattern" class="page__taxonomy-item" rel="tag">observer-pattern</a><span class="sep">, </span>
    
      
      
      <a href="/tags/#software-architecture" class="page__taxonomy-item" rel="tag">software-architecture</a>
    
    </span>
  </p>




  


  
  
  

  <p class="page__taxonomy">
    <strong><i class="fas fa-fw fa-folder-open" aria-hidden="true"></i> Categories: </strong>
    <span itemprop="keywords">
    
      
      
      <a href="/categories/#database" class="page__taxonomy-item" rel="tag">Database</a><span class="sep">, </span>
    
      
      
      <a href="/categories/#design-pattern" class="page__taxonomy-item" rel="tag">Design Pattern</a><span class="sep">, </span>
    
      
      
      <a href="/categories/#software-architecture" class="page__taxonomy-item" rel="tag">Software Architecture</a>
    
    </span>
  </p>


        
          <p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> Updated:</strong> <time datetime="2024-12-02T00:00:00-05:00">December 02, 2024</time></p>
        
      </footer>

      <section class="page__share">
  

  <a href="https://twitter.com/intent/tweet?text=Real-Time+vs+Persistent+Notifications%3A+Choosing+Between+Observer+Pattern+and+Databases%20https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--twitter" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on Twitter"><i class="fab fa-fw fa-twitter" aria-hidden="true"></i><span> Twitter</span></a>

  <a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--facebook" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on Facebook"><i class="fab fa-fw fa-facebook" aria-hidden="true"></i><span> Facebook</span></a>

  <a href="https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmahedee.net%2Freal_time_vs_persistent_notifications_observer_pattern_or_databases%2F" class="btn btn--linkedin" onclick="window.open(this.href, 'window', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" title="Share on LinkedIn"><i class="fab fa-fw fa-linkedin" aria-hidden="true"></i><span> LinkedIn</span></a>
</section>


      
  <nav class="pagination">
    
      <a href="/leveraging_the_observer_design_pattern_10_real_world_examples_in_action/" class="pagination--pager" title="Leveraging the Observer Design Pattern : 10 Real-World Examples in Action
">Previous</a>
    
    
      <a href="/how-to-enable-disable-adsense-jekyll-minimal-mistakes/" class="pagination--pager" title="How to Enable and Disable AdSense in Jekyll Minimal Mistakes Blog
">Next</a>
    
  </nav>

    </div>

    
      <div class="page__comments">
  
  
      <h4 class="page__comments-title">Comments</h4>
      <div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v18.0&appId=1641495303280571"></script>

<div class="fb-comments" 
     data-href="https://mahedee.net/real_time_vs_persistent_notifications_observer_pattern_or_databases/" 
     data-width="100%" 
     data-numposts="10"
     data-colorscheme="light"
     data-order-by="social"
     data-mobile="true">
</div>
    
</div>

    
  </article>

  
  
    <div class="page__related">
      <h4 class="page__related-title">You May Also Enjoy</h4>
      <div class="grid__wrapper">
        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/2010-01-01-could-not-access-network-location-systemdriveinetpubwwwroot/" rel="permalink">
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  2 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">
</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/procedural-vs-object-oriented-programming/" rel="permalink">Procedural vs Object-Oriented Programming: Key Differences Explained
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  6 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">A comprehensive comparison of procedural and object-oriented programming paradigms, exploring their key differences, advantages, and practical applications i...</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/implementing-metrics-and-dashboards-dotnet-core-api-prometheus-grafana/" rel="permalink">Implementing Metrics and Dashboards for .NET Core APIs with Prometheus and Grafana
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  18 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">Step-by-step tutorial to implement metrics and dashboards for .NET Core APIs using Prometheus and Grafana for effective monitoring.
</p>
  </article>
</div>

        
          



<div class="grid__item">
  <article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
    
    <h2 class="archive__item-title" itemprop="headline">
      
        <a href="/my-vs-code-extensions-for-daily-development/" rel="permalink">My VS Code Extensions for Daily Development Work
</a>
      
    </h2>
    
      <p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> 




  3 minute read
</p>
    
    <p class="archive__item-excerpt" itemprop="description">A comprehensive list of VS Code extensions I use daily for development, productivity, and coding efficiency across multiple languages and frameworks.
</p>
  </article>
</div>

        
      </div>
    </div>
  
  
</div>

  
  <!-- AdSense disabled:
  <ins class="adsbygoogle"
       style="display:block"
       data-ad-client="ca-pub-xxxxxxxxxx"
       data-ad-slot="xxxxxxxxxx"
       data-ad-format="auto"
       data-full-width-responsive="true"></ins>
  -->
</div>

<!-- Before closing body tag -->
<!-- AdSense disabled: Global AdSense script
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxx"
        crossorigin="anonymous"></script>
-->

Step 3: Comment out ad code in include files (optional extra safety):

_includes/advertisements.html

<!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxx"
     crossorigin="anonymous"></script>
<!-- Horizontal Unit -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-xxxxxxxxxx"
     data-ad-slot="xxxxxxxxxx"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
-->

_includes/vertical_advertisement.html

<!-- AdSense Disabled
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxx"
     crossorigin="anonymous"></script>
<!-- vertical unit -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-xxxxxxxxxx"
     data-ad-slot="xxxxxxxxxx"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
-->

Method 3: Environment-Based Control (Advanced)

Create different configurations for different environments:

_config_local.yml (Development)

# Disable ads for local development
adsense:
  enabled: false

_config_production.yml (Production)

# Enable ads for production
adsense:
  enabled: true

Then modify your ad includes to check the configuration:


Best Practices

1. Test Thoroughly

  • Always test your ads in a staging environment first
  • Use AdSense’s test mode when available
  • Verify ads display correctly on different devices

2. Performance Considerations

  • AdSense scripts are loaded asynchronously to minimize impact
  • Consider lazy loading for below-the-fold ads
  • Monitor site performance after enabling ads

3. User Experience

  • Don’t overwhelm users with too many ads
  • Ensure ads are clearly distinguishable from content
  • Consider ad placement carefully for optimal user experience

4. Compliance

  • Follow Google AdSense policies
  • Ensure your site has proper privacy policy
  • Include ads.txt file for better ad security

Troubleshooting

Common Issues

  1. Ads still showing after disabling
    • Cause: AdSense code exists in multiple locations
    • Solution: Check both _layouts/single.html AND _layouts/default.html
    • Search for googlesyndication or adsbygoogle across all files
    • Rebuild production site: ./build-production.ps1
  2. AdSense code in unexpected places
    • Use search: grep -r "adsbygoogle" . or grep -r "googlesyndication" .
    • Check all layout files: default.html, single.html, home.html
    • Verify include files are actually commented out
  3. Caching issues
    • Clear browser cache and cookies
    • Clear CDN cache if using one
    • Hard refresh (Ctrl+F5) the website
    • Check in incognito/private browsing mode

Verification Steps

  1. Check browser console for JavaScript errors
  2. Browser DevTools → Network tab: No requests to googlesyndication.com
  3. View page source: Search for adsbygoogle (should only find commented code)
  4. Console test: window.adsbygoogle should return undefined
  5. Check generated HTML: Verify _site folder contains commented ads only

Debugging Steps

  1. Check browser console for JavaScript errors
  2. Verify ad code syntax
  3. Use Google Tag Assistant for validation
  4. Test with different browsers and devices

Common Pitfalls

  • Missing default.html layout: Always check the base layout file
  • Incomplete commenting: Ensure HTML comments are properly closed
  • Multiple AdSense implementations: Some themes have ads in several places
  • Build cache: Always rebuild after making changes

Alternative Monetization Methods

If AdSense doesn’t work for your site, consider:

  • Direct sponsor partnerships
  • Affiliate marketing
  • Premium content subscriptions
  • Digital product sales
  • Patreon or donation platforms

Conclusion

Managing AdSense in a Jekyll Minimal Mistakes blog is straightforward once you understand the structure. The key is maintaining clean, organized code that can be easily enabled or disabled as needed. Always prioritize user experience while implementing monetization strategies.

Remember to regularly review your AdSense performance and policies to ensure optimal revenue and compliance.


Last Updated: January 1, 2025
Tested with: Jekyll 4.x, Minimal Mistakes theme
AdSense API Version: Current as of 2025

--> -->

Comments