Skip to main content

Refactoring Journey: From GistStateManager to Domain-Driven Components

· 4 min read

The Problem: A Growing "God Class"

In our Mercury trading bot project, we started with a seemingly simple class called GistStateManager. Its initial purpose was to manage state persistence using GitHub gists as a storage mechanism. However, as the project evolved, this class accumulated more and more responsibilities:

  1. Managing application state in Redis
  2. Reconstructing state from event streams
  3. Creating and updating GitHub gists
  4. Handling Telegram message updates
  5. Managing UI buttons and formatting
  6. Coordinating state transitions

This is a classic case of what we call a "god class" - a class that knows too much and does too much. Let's explore how we can refactor this into more focused, domain-driven components.

The Natural Evolution of Ansible: A Human Journey

· 3 min read
Max Kaido
Architect

When people start with Ansible, they often encounter tutorials showing a perfect directory structure with roles, playbooks, and inventories all laid out. But that's not how real adoption happens. Let me share a more natural journey of how teams typically grow into Ansible.

The Digital Oracle: Tale of the Hermes Algorithm

· 2 min read
Max Kaido
Architect

In the neon-lit depths of the Mercury trading matrix, where digital currencies pulse through virtual arteries like liquid light, there exists an entity known as Hermes - not the ancient messenger of gods, but a cutting-edge ranking oracle born from the fusion of classical wisdom and quantum mathematics.

Taming State Management in Market Ranking: Three Approaches

· 4 min read

When implementing complex algorithms like QuickSelect for market ranking, managing state correctly is crucial. We recently encountered a bug where partition arrays were being reset unexpectedly. Let's explore three different approaches to prevent such issues.

The Problem

Our QuickSelect implementation for market ranking had a subtle bug where partition arrays were being reset during comparisons:

// Bug manifestation
[34/73] Sizes: better=5, equal=1, worse=11
[35/73] undefined vs MFERUSDT -> undefined (undefined)
[36/73] Sizes: better=5, equal=1, worse=11

The root cause? Mixing mutable and immutable patterns in state management. Let's explore three solutions.

Embracing the Fear: A Developer's Journey Through Uncertainty

· 3 min read
Max Kaido
Architect

It's 3 AM, and I'm staring at my code editor. The soft glow of the screen illuminates a room that's become both my sanctuary and my prison. Today was my last day at my "real" job. I lost it because I was too focused on building Mercury and TonArcana. The irony doesn't escape me – I lost my safety net because I believed too much in what I was building.

Efficient Market Ranking with QuickSelect Algorithm

· 2 min read
Max Kaido
Architect

In the latest update to Mercury Bot (v0.126.0), we've introduced a significant improvement to our market ranking system using the QuickSelect algorithm. This optimization reduces the number of comparisons needed to find the top K markets, making our analysis more efficient and responsive.

The Challenge

Our previous implementation compared every market with every other market to establish rankings. With N markets, this resulted in O(N²) comparisons. For 100 markets, we needed up to 4,950 comparisons! This was:

  • Time-consuming
  • Resource-intensive
  • Expensive in terms of API calls

The Art of Pain: A Tale of Kubernetes Ingress Configuration

· 3 min read

Date: January 20, 2025

Today, I want to share a story about the intricate dance between Kubernetes, Ingress Controllers, and SSL certificates - a tale that many DevOps engineers might find painfully familiar.

The Setup

Picture this: A seemingly straightforward task of setting up an Ingress Controller with SSL certificates for two domains. The players in our story:

  • An NGINX Ingress Controller
  • cert-manager for SSL certificate management
  • Let's Encrypt as our certificate authority
  • MetalLB for load balancing in a bare metal environment

Act 1: The Initial Deployment

Everything started smoothly. The Ingress Controller deployment went up without complaints, MetalLB assigned our IP address, and cert-manager was ready to do its magic. But as we all know, in the world of Kubernetes, silence often precedes the storm.