<?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: Digital</title>
    <description>The latest articles on Forem by Digital (@digital39999).</description>
    <link>https://forem.com/digital39999</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%2F1172505%2Ff7ddf150-fd43-4f68-8dca-eb09e6b23edc.jpeg</url>
      <title>Forem: Digital</title>
      <link>https://forem.com/digital39999</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/digital39999"/>
    <language>en</language>
    <item>
      <title>Introducing Redis Scheduler</title>
      <dc:creator>Digital</dc:creator>
      <pubDate>Sat, 10 Aug 2024 07:52:54 +0000</pubDate>
      <link>https://forem.com/digital39999/introducing-redis-scheduler-459e</link>
      <guid>https://forem.com/digital39999/introducing-redis-scheduler-459e</guid>
      <description>&lt;h2&gt;
  
  
  A Scalable Solution for Timed Tasks in Microservices
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why Redis Scheduler?
&lt;/h3&gt;

&lt;p&gt;If you've ever struggled with managing timed tasks in your microservices, you're not alone. Traditional methods like intervals and cron jobs might seem convenient, but they come with several pitfalls:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scalability Issues&lt;/strong&gt;: Cron jobs are tied to a single server, which makes scaling your application a challenge.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single Points of Failure&lt;/strong&gt;: If your server goes down, your scheduled tasks may be lost or delayed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Inefficiency&lt;/strong&gt;: Running frequent tasks consumes unnecessary resources, even when there's nothing to process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complex Time Management&lt;/strong&gt;: Handling time zones and daylight saving changes can be tricky and error-prone.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Redis Scheduler: A Better Approach
&lt;/h3&gt;

&lt;p&gt;Redis Scheduler is a microservice designed to address these challenges by using Redis as a reliable backend for scheduling tasks. Here’s how it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Easy Task Scheduling&lt;/strong&gt;: Simply send a request with a TTL (Time-To-Live) and a webhook URL, and Redis Scheduler will take care of the rest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatic Retries&lt;/strong&gt;: If a webhook fails, Redis Scheduler will automatically retry it based on configurable retry settings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Horizontal Scalability&lt;/strong&gt;: Redis Scheduler can run across multiple instances, distributing the workload effectively.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persistent and Reliable&lt;/strong&gt;: Tasks are stored in Redis, ensuring they persist even if the service restarts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to Get Started
&lt;/h3&gt;

&lt;p&gt;Redis Scheduler is containerized, making it easy to deploy with Docker or Docker Compose. Here's a quick start:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pull the Docker Image&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker pull ghcr.io/digital39999/redis-scheduler:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run the Container&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;REDIS_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"redis://your-redis-url:6379"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;API_AUTH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your-api-auth-token"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;8080 &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;RETRIES&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;5 &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;RETRY_TIME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;60 &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-p&lt;/span&gt; 8080:8080 &lt;span class="se"&gt;\&lt;/span&gt;
     ghcr.io/digital39999/redis-scheduler:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Schedule a Task&lt;/strong&gt;: Use the &lt;code&gt;/schedule&lt;/code&gt; endpoint to create a new task that will trigger a webhook after the specified TTL.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST http://localhost:8080/schedule &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer your-api-auth-token"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{
  "webhook": "https://example.com/webhook",
  "ttl": 120,
  "data": {
    "message": "Hello, World!"
  }
}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Redis Scheduler provides a scalable, reliable, and efficient solution for managing timed tasks in your microservices. Whether you're dealing with simple delays or complex workflows, Redis Scheduler is designed to make task scheduling easier and more robust. &lt;/p&gt;

&lt;p&gt;Check out the &lt;a href="https://github.com/Digital39999/redis-scheduler" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; for more details, and start integrating Redis Scheduler into your projects today!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>productivity</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
