Humble Software Reader, Writer and DevOps Builder, with love for Classical Music.

Setting Up TimescaleDB on AWS
TimescaleDB is a PostgreSQL extension for high-performance real-time analytics on time-series and event data. It is basically a custom Postgres. Important: This post uses Terraform to create and destroy resources on an AWS account. Make sure that you destroy the resources as soon and as long as you don’t need them any more. Otherwise, you will be charged more than you might want.How do you set up a TimescaleDB on AWS?Unfortunately, you can’t use, at the time of this writing (Jul 2025), the ma...

Setting Up TimescaleDB on AWS
TimescaleDB is a PostgreSQL extension for high-performance real-time analytics on time-series and event data. It is basically a custom Postgres. Important: This post uses Terraform to create and destroy resources on an AWS account. Make sure that you destroy the resources as soon and as long as you don’t need them any more. Otherwise, you will be charged more than you might want.How do you set up a TimescaleDB on AWS?Unfortunately, you can’t use, at the time of this writing (Jul 2025), the ma...

Querying a Daily Stats Table - Postgres
Hero Image by Panos Matsinopoulos on ZoraThe TableI have a table named daily_stats, which keeps track of some daily metrics. Here it is:Example rows from table \`daily_stats\`The structure of the table:-- CREATE TABLE "daily_stats" ---------------------------------- CREATE TABLE "public"."daily_stats" ( "id" BigInt DEFAULT nextval('daily_stats_id_seq'::regclass) NOT NULL, "metric" Character Varying NOT NULL, "date" Date NOT NULL, "count" BigInt DEFAULT 0 NOT NULL, "lock_version" BigInt DEFAUL...

Querying a Daily Stats Table - Postgres
Hero Image by Panos Matsinopoulos on ZoraThe TableI have a table named daily_stats, which keeps track of some daily metrics. Here it is:Example rows from table \`daily_stats\`The structure of the table:-- CREATE TABLE "daily_stats" ---------------------------------- CREATE TABLE "public"."daily_stats" ( "id" BigInt DEFAULT nextval('daily_stats_id_seq'::regclass) NOT NULL, "metric" Character Varying NOT NULL, "date" Date NOT NULL, "count" BigInt DEFAULT 0 NOT NULL, "lock_version" BigInt DEFAUL...

Singleton, Unique Jobs, Concurrency - Ruby on Rails
Hero Image by Ahmad Bello from PixabayIntroductionIn a Ruby on Rails project, creating a job to run in the background is as simple asDefining the job class / execution codeSending a job instance into a queueHave a worker execute that instanceBut all things that can go wrong when multiple users are trying to access the same shared state, a.k.a. concurrency issues, the same wrong things can happen when multiple processes / threads (let’s call them workers) are trying to execute a background tas...

Singleton, Unique Jobs, Concurrency - Ruby on Rails
Hero Image by Ahmad Bello from PixabayIntroductionIn a Ruby on Rails project, creating a job to run in the background is as simple asDefining the job class / execution codeSending a job instance into a queueHave a worker execute that instanceBut all things that can go wrong when multiple users are trying to access the same shared state, a.k.a. concurrency issues, the same wrong things can happen when multiple processes / threads (let’s call them workers) are trying to execute a background tas...

SQL Query Annotation
Context:Ruby on RailsPostgresActiveRecordProblem:When I inspect the SQL queries stats in my Postgres database, I want to know where each one is coming from, in terms of application code. As precisely as possible. The pg_stat_activity , for example, has the column query which shows the SQL statement:- START_REPLICATION SLOT "..." 539/C0000000 TIMELINE 1 - COMMIT - SELECT "github_accounts".* FROM "github_accounts" WHERE "github_accounts"."name" = '...' ORDER BY "github_accounts"."account_create...

SQL Query Annotation
Context:Ruby on RailsPostgresActiveRecordProblem:When I inspect the SQL queries stats in my Postgres database, I want to know where each one is coming from, in terms of application code. As precisely as possible. The pg_stat_activity , for example, has the column query which shows the SQL statement:- START_REPLICATION SLOT "..." 539/C0000000 TIMELINE 1 - COMMIT - SELECT "github_accounts".* FROM "github_accounts" WHERE "github_accounts"."name" = '...' ORDER BY "github_accounts"."account_create...

Find Long Ruby on Rails Requests
Image by G Poulsen from PixabayIntroductionAt Talent Protocol we use Ruby on Rails for our back-end server.Problem DefinitionHow do we know which HTTP requests take too long to be processed? With too long we mean more than 2 seconds.SolutionAWS CloudWatch LogsWe collect all Rails server logs into AWS CloudWatch. Hence, when we inspect the logs we can see lines like the following:Rails Log LinesCompleted OK - More than 2 SecondsSo, it is quite easy to select the lines individually. For example...

Find Long Ruby on Rails Requests
Image by G Poulsen from PixabayIntroductionAt Talent Protocol we use Ruby on Rails for our back-end server.Problem DefinitionHow do we know which HTTP requests take too long to be processed? With too long we mean more than 2 seconds.SolutionAWS CloudWatch LogsWe collect all Rails server logs into AWS CloudWatch. Hence, when we inspect the logs we can see lines like the following:Rails Log LinesCompleted OK - More than 2 SecondsSo, it is quite easy to select the lines individually. For example...