Optimistic vs. Pessimistic locking in Rails

While performing concurrent operations, a database must ensure data integrity. ACID compliant relational database ensures this data integrity through its locking mechanism. ACID = Atomicity, Consistency, Isolation, Durability Locks can be at the database, table, page, or row level. Here is a beginner's guide to database locking in PostgreSQL. In this article, let's see how Rails provides a mechanism for optimistic locking on ActiveRecord models. However, before we proceed, let us first understand the basics of optimistic and pessimistic locking. What is optimistic locking? Let's take an example of two admin users, Mohan and Ritesh, managing the product inventory in their

How we automated our recruitment process using Zapier, Airtable & Trello

As a tech organisation, we always strive to find suitable talent for available positions, and then move them quickly through the application funnel, from sourcing to hiring. The goal is to onboard a potential candidate as fast as possible. In this endeavor, we decided to automate our recruitment processes so that the overall time to screen, interview and to release an offer is relatively faster. Background Interested candidates apply on our website through careers page. We have a referral program for our associates so it also resulted in wider interest. We also receive direct applications through email on careers@kiprosh.

Auto startup scripts for services and apps

One of our production web application runs on a dedicated node in DO (Digital Ocean) cloud server. This web application has following services running. Elixir Phoenix API server React.js client server Redis caching server Bots (Slack) Few days back, Digital Ocean triggered an urgent maintenance for Meltdown and Spectre Mitigations resulting into a reboot of our PROD server. DO did alert us in advance by sending an email notification with schedules. But seems we missed these schedules accidentally. Thus, our PROD web application was suddenly down after this auto reboot / restart by DO forced maintenance. We realised that we

Ecto queries using "fragment" in Elixir

Ecto’s query syntax does not cater to all types of database queries. fragment is useful to inject custom SQL for composing queries. Lets take a very simple example to lowercase a target column while comparing a string in where clause in our SQL query. We can usefragmentto inject custom SQL into our query. email = "test@hello.com" query = from u in User, where: fragment("lower(?)", u.email) == ^email, select: u.email Repo.all query In the example above, we have used lower using fragment to lowercase (i.e. downcase) the email column. This will generate

Elixir - How to run Ecto queries from within a custom mix task

Reading Time: 4 mins While writing a custom Mix task in Elixir, I ran into minor challenges for running / executing an Ecto query to update a database table column from within my mix task. It was not straightforward initially thus I thought to share here. In this short article, we will also see how to pass arguments to our mix task to run dynamic query. First, what is Mix? Elixir documentation says: Mix is a build tool that ships with Elixir that provides tasks for creating, compiling, testing your application, managing its dependencies and much more. Mix build tool is

Scaling Enterprise SaaS Platform with Microservices

Spoiler Alert: This article is not about Microservices architecture or how microservices works. In this article, I will share what we have learned in scaling one of the large SaaS platform, our ongoing improvements and how Microservices architecture is playing a key role in scaling this SaaS platform. This SaaS Platform has experienced tremendous growth in the past 18 months. It has now become one of the leading CRMs in North America. Everyone’s definition of “scale” and “growth” can differ based on specific numbers or metric a company is targeting i.e. revenue, user base, or others. We are

Interesting feature of Elixir: Documentation as Tests

One of the coolest feature I came across in Elixir - our code documentation becomes our unit tests. I was amazed by its simplicity when I saw it in action in sample app I was writing. I feel this is one of the most incredibly and helpful feature I saw in any modern programming language in recent times. (Python has similar functionality using Python’s doctest.) Let me explain this by giving a quick demo using few simple examples: Math functions sum and multiply. Lets say this is our Maths module defmodule Maths do def sum(num1, num2) do num1

General tips & tricks for Ruby on Rails code

Here are few Ruby on Rails and general developer tips & tricks to improve code readability do things Rails way improve productivity They say "Good code is like a good joke: It needs no explanation". 1) idiomatic code Instead of this code... def delete(notes) notes = notes.where('type = (?)', 'evernote') notes.any? && notes.map(&:destroy) end Better way is... def delete(notes) notes.where('type = (?)', 'evernote').map(&:destroy) end 2) Refactor Instead of this code identifier = resource.social_identifier data = { identifier: identifier } render json: data.to_json Prefer this? render json: { identifier:

Gem JSON - Error installing gem with native extension for Ruby 2.2.2

We recently upgraded one of our app to Ruby 2.2.2 Bundle installed failed ...... crying about well known issue of Error installing gem with native extension, but this time for Gem json -v 1.8.3 Detailed error shows Fetching: json-1.8.3.gem (100%) Building native extensions. This could take a while... ERROR: Error installing json: ERROR: Failed to build gem native extension. /usr/local/rvm/rubies/ruby-2.2.2/bin/ruby -r ./siteconf20151209-13741-vqcxt1.rb extconf.rb creating Makefile make "DESTDIR=" clean make "DESTDIR=" compiling generator.c linking shared-object json/ext/generator.so /usr/

Sample ToDo app using React

I started learning React and developed a ToDo list application. Here is the github repo for this ToDo web application. This ToDo application has following functionality: add a new ToDo item inline edit an existing item delete an item drag & drop to sort or change the order This app is without any backend to keep things simple for now. I have used jQuery plugin jquery-editable for inline text editing of ToDo item. The mindset that we should not think jQuery way to implement UI in React helped me to implement or mix jQuery in correct way i.e. we