Unhidden Gems: 4 Highlights from Our Recent Ruby on Rails Sessions

Catch a glimpse of what we’ve recently covered on our Ruby on Rails team knowledge-sharing sessions. This is a selection of our latest exchanges on Monorepos, WebSockets, Rails 7 and Sidekiq.

Whitespectre
Whitespectre Ideas
6 min readAug 18, 2022

--

by the Whitespectre Rails Team

What you’ll find in this article:

  • What are the X-Rails Sessions
  • Implementing WebSocket Connections with Rails
  • Using Sidekiq to Improve Performance
  • Keeping Up with Rails 7
  • Optimizing the Workflow with a Monorepo

Sharing our knowledge is a core part of Whitespectre’s DNA. One of the main ways we do that across the company is through our different knowledge-sharing sessions. These range from open-topic sessions, like our company-wide “Brown Bag’’ talks, to more specific group meetings built around a platform or technology, such as React, React Native, Blockchain, Product UI/UX, Frontend, and, of course, Ruby on Rails.

As Nick Tudor, the company’s CEO, explains, “We believe strongly that our technical capabilities are strengthened by sharing knowledge and experiences across our projects and team members. Our cross-team (X-team) sessions are a structured but informal opportunity to talk with fellow engineers, share what we’ve been doing, learn from others, and debate different approaches. These sessions help build the Whitespectre “brain trust”, which makes us collectively smarter and more efficient at building software”.

The X-Rails Sessions

The X-Rails sessions gather our Ruby on Rails developers community every three weeks. On each one, one engineer does a short presentation on something interesting they’ve recently dealt with on a project and that then kick-starts the discussion for the whole group.

Rafał Jamróz, Senior member of the Rails group, explains that “the goal is to make sure that people from different teams with similar skill sets meet together and discuss interesting new additions to their tools/frameworks or how they solved a challenge in their project. These meetings have sparked a lot of interesting discussions and allowed people to discover cool ideas, tools, and solutions that their peers on different projects are working on”.

The following are just some of the topics shared recently by senior members of the X-Rails Team: Diogo Rosa, Ricardo Leitao, Rafał Jamróz, Marc Camara, and Konstantin Neperuchenko.

Implementing WebSocket Connections with Rails

Over the past three years, among other Rails projects, Whitespectre has created two complex platforms and applications centered on hardware and software integration. These are Idion — an innovative remote patient monitoring device — , and SpotOn — a virtual fence creator and collar tracker for dogs — .

Idion’s healthcare platform needed custom software to integrate the hospitals’ electronic medical records system with its cloud platform. This would enable custom Shields; to be printed on patient arrival. Diogo explained how they reverse Engineered a WebSocket-based print-server and built the solution using Rails.

This specific printer used legacy technology on the backend (JAVA with Tomcat) that could be enhanced using a JAVA SDK. From the tech point of view, it was challenging to maintain two applications with different and outdated SDKs. So the solution was to reverse engineer the printer WebSockets protocol and build a rails server to communicate with it, making it easier to wrap this as an API service. The goal was to use Rails WebSockets libraries instead of action cable right away, understand how they worked, and make them function according to the printer-specific WebSockets requirements.

SpotOn, on the other hand, is a GPS collar for dogs that required us to develop their brand new app to allow dog owners to create wireless GPS fences and take their dogs and virtual fences wherever they go.

Ricardo shared his team’s steps to connect the app with the collar based on Bluetooth, GPS, and cellular technologies. Velocity and reliability in the flow of data were a must since the app would have to handle the virtual fences that go from ½ an acre to more than 1,000 acres while also monitoring and tracking the behavior of the dogs. The team behind the app managed to achieve this with a combination of live WebSocket connections, action cables to make it easier on the tech side, and cellular to keep a live connection to the collar.

Using Sidekiq to Improve Performance

Purple Carrot is a platform that disrupted the meal kit space with a mission to make plant-based exciting and accessible for meal kit subscribers.

When his team was tasked with processing significant amounts of data and generating extensive reports on demand, Rafal Jamroz and his team recurred to Sidekiq. Rafal explained during an X-Rails Session, that this is a commonly used tool for background processing in the Ruby world. Still, it was the batch-processing capabilities that made it an excellent fit for this job, mainly because of its outstanding performance.

Sidekiq Batch (requiring Sidekiq Pro, but there’s a free open-source alternative) was used to split data-heavy jobs processed in multiple threads, and callbacks were used to combine the results and then clean up. The callbacks can also be used to act on failures by sending a notification (Slack in our case)

The project also needed another type of worker to push order information to third-party services (also using batches). In this case, they used the ShipUp service to track shipments and notify customers when a box gets delivered or about shipping delays. This service had an API rate limit, and thus they couldn’t submit more than 120 requests per minute. In this case, the solution was to use a self-rescheduling job based on the redis_rate_limiter gem.

Keeping Up with Rails 7

Being up to date with the latest releases in the Ruby world is key for the health of all projects, and Marc has recently talked about some very useful gems that come with Rails 7, which in some cases are promoted as the new standard to be used with Rails 7 applications.

With Import Maps, instead of getting all javascript files and compiling them into one huge js file, you can rely on http2 to retrieve all packages in different requests. This has the benefit of being easier to cache and easier to see where something went wrong.

Propshaft is an alternative asset pipeline for Rails. In short, it’s faster and simpler than sprockets and the app does not need lots of changes to replace one for another

Kredis is a gem that makes using Redis easier than ever, by reading and writing it as if it was a huge hash living in the application. It also contains helpers for ActiveModel that can come in handy in many cases.

Finally, Marc introduced Hotwire, a Turbo + stimulus that only uses Ruby to make writing dynamic pages easier.

Optimizing the Workflow with a Monorepo

Konstantin and Diogo explained how they turned a cumbersome workflow of a big SaaS into a seamless experience by moving from a Multirepo to a Monorepo approach.

While reviewing the SaaS, they considered various options to develop a Ruby on Rails solution that was customizable for each client but that still shared functionalities via libraries.

The approach, which consists of merging all the projects and their dependencies into one repository, means that each project’s versions of gems will stop being used, and they will all use the current version.

They explained how everything changed on the CI/CD, the folder organization, and the GIT process. However, that wasn’t the biggest deal. A game-changer for the everyday developer’s work was a series of scripts they created to run several vital functions. You can read an in-depth take on this approach in this article.

Don’t forget to 👏🏻 if you enjoy reading our articles!

And subscribe to be the first to know what we are talking about 💡

--

--

Whitespectre
Whitespectre Ideas

Posts from our team on the latest in technology, design, and product strategy. See what we’re up to at https://www.whitespectre.com/