In this article I’ll consider two common approaches to implementing depth-first search and breadth-first search in Ruby.

Tree

Ruby has no built-in class for initializing Binary Tree data structure. Tree is just a restricted form of a Graph which have a parent-child relationship.

Here is the simplest definition for a binary…

What is the difference, how and when to apply?

Stub

A stub is the only defined result of the method call which doesn’t care about behavior. With RSpec, you can use stub with allow and receive methods.

allow(object).to receive(:method_name)

If you need to stub the result of the method then it’s possible with and_return

allow(object).to receive(:method_name).and_return(example_value)

Mock

Mock expect methods to…

Failure Management, Fallbacks, Exponential backoff, Tools and Patterns

When designing modern applications on microservices architecture and systems based on cloud solutions such as AWS, Azure, or Google Cloud imply the need to handle expected failures.

How to handle failures?

  1. Restarting the code in the current thread runtime
  2. Retry execute in background jobs

Retry failed code

We can represent the simplest retry in runtime as a…

How to manage encrypted keys for different environments

There are two most popular ways to manage secrets in your application.

  1. Encrypted file with secrets. Best choice for a single monolith application. There’s no need for additional software, just keep your encrypted data in the app repository and move decrypt key under git ignore.
  2. Centralized storage. For large and…

A tool for monitoring SQL queries in Rails

Get notified about slow queries

In the early stages of development, it may be useful to identify slow queries in time (when you don’t have a paid APM). QueryTrack helps to get notified about slow queries with related data: duration and backtrace.

https://github.com/kirillshevch/query_track

Installation

Add this line to your application’s Gemfile and then execute bundle install:

Publish/Subscribe Pattern with Message Brokers and usage of core concepts. Asynchronous execution of the application parts.

One of the tools that are rarely covered in the Ruby/Rails world are the message brokers (probably because they mostly written in Java). Everyone are familiar mostly with background jobs processing, but message brokers offer a more flexible approach to asynchronous execution. …

The main purpose of caching is making the application work faster. But also this mechanism can help to more flexibly manage data, a good example is session management.

Redis cache store

Rails 5.2 introduced built-in Redis cache store, which allows you to store cache entries in Redis.

To use Redis as a Rails cache store, use a dedicated cache instance that’s set up as an LRU (Last Recently Used) cache instead of pointing the store at your existing Redis server, to…

Module bundling, Loaders, Plugins, Babel

Webpack is a module bundler for modern JavaScript applications. The import and export statements have been standardized in ES2015. They are not supported in browsers yet, but webpack does support them out of the box. But actually it’s more powerful tool which can help us build whole our front-end.

Installing

Let’s…

Kirill Shevchenko

Software Engineer. Interested in Full-Stack Development and DevOps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store