Video summary

Golang Microservices Full Course #15 - Background Scheduler (Cron Job)

Main summary

Key takeaways

Technology

Summary

This episode introduces asynchronous background processing in a Go microservice using a cron scheduler. The goal is to run periodic maintenance and reporting tasks without making user-facing requests wait.

Implementation and key features

  • Adds the github.com/robfig/cron/v3 library and creates an internal scheduler module.
  • Initializes the scheduler with database access and wallet and ledger repositories, then starts it alongside the HTTP server.
  • Implements or outlines four scheduled jobs:
    1. Expired OTP cleanup — intended to run every 30 minutes. Since the OTP table is not yet available, the job logs that cleanup is skipped.
    2. Daily balance reconciliation — reads wallet balances, calculates balances from ledger entries, and logs any mismatches. The instructor suggests adding Slack or Telegram alerts for mismatches in production.
    3. Expired refresh-token cleanup — intended to run daily at 3:00 a.m. Since the refresh-token table is not yet available, the job skips cleanup for now.
    4. Daily transaction CSV export — queries transactions for the current date and writes a CSV report to a reports directory.
  • Uses contexts with timeouts. Jobs log their progress and errors, along with affected-row counts or the number of exported records.
  • Temporarily configures a test job to run every 10 seconds, then removes that configuration.

Graceful shutdown

The tutorial also covers graceful shutdown. The HTTP server stops accepting new requests and is given time to finish in-flight work. The scheduler is then stopped so active jobs can complete before dependent resources are closed. The instructor notes that shutdown ordering matters when scheduled jobs use the database.

Tutorial topics

  • Installing and wiring a Go cron scheduler
  • Defining periodic database maintenance and reconciliation jobs
  • Exporting daily transaction data to CSV
  • Starting and stopping the scheduler with the application
  • Testing scheduled execution and handling graceful shutdown

Main speaker/source: The instructor from the Ikhda Muhammad Wildani channel.

Rate this summary

Your feedback will help improve summaries.

Improve this summary

Reprocess with a stronger model when the summary feels incomplete or inaccurate.

Pro

Translate summary in another language

Pro

Ask questions to this video

Chat for follow-up questions, clarifications, and source-backed answers.

Coming soon

Share this summary

Original video