Optimising wedding aggregator code in Ruby on Rails

Optimising wedding aggregator code in Ruby on Rails

July 10, 2024

“A quarrel with your wife is like a concert. First the new releases, and lastly the most popular hits.”

Folk wisdom

The website with the self-explanatory name WEDby.ME helps couples make their dream wedding come true. In 2020, thanks to this service, more than 850 couples independently organised their turnkey weddings: from buying rings to booking banquet halls and holding a show program. Brides can easily select wedding dresses, bouquets, photographers, cakes, and over 100,000 other products from 2,403 companies in one place.

The venue boasts an impressive selection of more than 900 banquet halls, 1,500 restaurants, and nearly 5,000 wedding dresses. What about accessories? There are 1,174 items of hair accessories alone! All items can be filtered using detailed filters. Wedding rings, essential for any wedding, can be selected based on price, type, material, inserts, and their colours.

Note to thrifty newlyweds: catering on the website can be ordered from just $14 per person. And for the bride who wants to impress guests with her wealth, the “Alexandrite” bouquet is available for $1,144. By the way, did you know that for a wedding with 100 guests you need a cake weighing 15 kg? This “Handsome” cake is also available on the site!

exclamation mark in a circle

Important note: It is difficult to think of any wedding service not available on the WEDby.ME website. We couldn't. Be sure to write to us if you succeed.

Let's look at some statistical information. According to RBC and Avito Services analysts, a survey of 10,000 respondents throughout country recorded a 2-fold increase in demand for organising weddings and graduations in the summer of 2023. The greatest growth was observed in organising buffets (up 141% year-on-year), ordering toastmasters for events (up 98%), and all services related to wedding organisation (up 92%). In the premium segment, artists have been invited more often to weddings and corporate events, despite noticeable fee increases.

Choosing rings for a wedding
Choosing rings for a wedding

Among the top five main components of wedding costs, respondents included a cake (42% voted for it), flowers (35%), balloons (34%), a photographer or cameraman (29%), and rented premises (25%). Approximately one-fifth of newly wedded (22%) organise private events on their own, including baking cakes, buying bouquets in flower shops, organising photography, etc. The remaining 78%, according to the study, turn to specialists for help.

– Darling, do we have enough money for the wedding?

– Well, I was saving a little for a rainy day.

Analysts call weddings the most expensive celebrations. Every fifth person who had a wedding in the summer of 2023 spent between $1,111 to $3,333 on the organisation, and almost a quarter (23%) spent more than $3,333. Additionally, 3% of respondents organised a ceremony costing $11,111 or more.

On wedding marketplaces, including WEDby.ME, it is possible to transfer all the hassles of organising a celebration to professionals, allowing newlyweds, their parents, and friends to spend time with loved ones.

The bride's bouquet
The bride's bouquet

The company's owners sought specialists to refine and provide ongoing technical support for a website written in Ruby, Ruby on Rails, and JavaScript. The most important components of online service quality are the speed and ease of site use.

We began the audit by describing the intricacies of the current implementation and creating a list of defects. The next step involved the senior developer preparing a detailed technical specification for code refactoring, describing redundant and suboptimal code. The customer agreed to optimise the integration code with the BookBanket service.

Performance issues

01 Server cache Server cache The server cache has been optimised. More precisely, work with the server cache was completely removed as it was not used for its intended purpose.
02 Rendering delays Rendering delays The second significant problem was the excessive delay in server rendering of the “Banquet Halls” section.
03 Phantom filter Phantom filter The third defect involved the sudden disappearance of restaurants from the “Banquet Halls” section.
04 Pagination errors Pagination errors Fixed issues with the paginator and banquet hall counter. Functions did not work correctly, sometimes showing arbitrary values.
05 Suboptimal queries Suboptimal queries The next problem was redundant and inefficient queries to the DBMS. Profiling, debugging, and query optimization were required.
06 Impossibility of development Impossibility of development Without refactoring, the service was not ready for scaling, which could lead to customer churn.

Code refactoring

The main achievement of the refactoring was a significant reduction in the rendering time of the “Banquet Halls” section on the server. This was achieved by transferring interaction with the BookBanket service to a background process running on a schedule. Previously, data was received in real time, which greatly slowed down the process. Restaurant parameters required for sorting and filtering are now saved to the site database, and SQL queries have been redesigned and optimised.

Before refactoring, all restaurants and banquet halls were queried, not just those needed by the current page. Under the previous implementation, adding new restaurants would inevitably increase already unacceptable page load times.

Artist for a wedding
Artist for a wedding

Several tables contained obsolete records that were no longer used. For such tables, scheduled cleaning and packing scripts have been added. For example, the time for the simplest query to the vieweds table was 13 seconds, and the number of records was about 10 million. Records older than 120 days were deleted, and packing the table with the VACUUM command reduced the size from 9 gigabytes to 37 megabytes.

Before refactoring, the server cache was used irrationally. It was not used to reduce the number of API requests or database calls but as an intermediate means of storing and transferring data between multiple methods. The values from the cache were not reused during the server rendering process but were constantly updated, which did not provide any performance gain. Some fields stored in the cache required sorting and searching. Instead of using fast DBMS tools, the task was performed in an application-level language, resulting in more complex code, an increase (not a decrease!) in the number of database queries, and a loss of performance. Excess code that turned out to be meaningless after refactoring was removed.

Banquet halls for weddings
Banquet halls for weddings

A restaurant was hidden if, for example, a network error occurred during an API request or if BookBanket was temporarily unavailable. Since the errors were random, requests for the same page would display different lists of establishments.

In addition to refactoring, multiple changes were made to the layout and functionality of several sections of the site. Defects in ranking banquet halls by price and cost calculation methods were corrected, improving the user experience. Adding SMS authorization to the site also made the user experience more convenient. Finally, bugs with the page counter and paginator were fixed.

Instead of a conclusion

“I'm a wedding photographer. And do you know what's the saddest thing about my profession? The fact that I have regular customers.”

Alexander Pimenov

There is confidence that work on the site will always be relevant. Over time, new functions, sections, and business areas will be added. After all, the number of weddings does not change much from year to year, and for every 10 marriages, there are up to 7 divorces (Rosstat statistics for 2021), constantly replenishing the pool of potential clients. This means there will be plenty of work for wedding aggregators.