Big refactoring: Fix that app for Fund That Flip
Share this post on
Our acquaintance with the fascinating world of fintech began in 2013 when Martians worked on a mobile-only banking startup for a local market. Next, we dived into the real estate industry thanks to the leading co-living platform Common, where Evil Martians kickstarted the mobile application. The project with Fund That Flip, the fintech platform for real estate investing, united these two worlds.
Evil Martians have been working closely with the Fund That Flip team for over a year, engaged in projects ranging from large-scale core refactoring to frontend optimization.
This project showed the crucial impact of continuous refactoring on any financial platform with a legacy codebase—even if it affects core systems that are so scary to mess with. Martians have been optimizing the backend and frontend of this Ruby on Rails application and introducing modern development tools and best practices that accelerated the development process and reduced time to run tests thrice. The project has brought some visible financial results for Fund That Flip in the market’s trying times.
Flipping the real estate investments market
Fund That Flip is a leader in online lending that specializes in funding rehab and new construction projects in the single-family residential market. The fix-and-flip real estate industry is now peaking due to high returns from investments and popularized in mainstream culture by TV shows like “Fixer Upper” or “Rehab Addict” and dozens of YouTube videos. However, securing the capital needed to finance projects for a real estate business can be an outdated and difficult process. Fund That Flip gives borrowers access to fast, reliable capital while simultaneously creating opportunities for accredited investors to build wealth by investing in loans through an online marketplace.
Matt Rodak and his partners launched Fund That Flip in 2014 after completing 300 flips on their own. In 2019 and 2020, the company was ranked on the Inc. 5000 list of the fastest-growing private businesses in the United States. In 2020, the project was featured as the #17 Fastest Growing Company in America by Financial Times’ rating. Fund That Flip has received many other awards for accelerated growth and innovative culture, including those for industry thought leadership, great workplace, smart culture, and Founders to Watch Award.
Fund That Flip raised $2M in their Seed round and then secured $11M in Series A financing, which brings the startup’s total funding raised to nearly $13M. It was supported by growth equity firm Edison Partners, which has an impressive track record of investing in market leaders and many first-movers. With this support and a six-year Job Creation Tax Credit they got from Ohio Tax Credit Authority, the company was able to expand their Cleveland office to complement their New York headquarters.
Refinancing for rehabbing
If you ever experienced short-term loans for real estate purposes, you understand how painful the borrowing process can be. Traditional lenders like banks hold flipping as a risky proposition and are not eager to finance a purchase of a residence that is not primary. That’s why many of them force borrowers to fill out long-form applications and wait up to 8 months for a loan approval. So-called “hard money lenders” demand double-digit interest rates on such loans.
On the flip side, many would-be homebuyers in the US face numerous challenges. Millions of properties are demanding significant investment to meet buyer preferences while building materials costs are getting higher. Besides, the market is witnessing the rise of a whole new generation of real estate redevelopers who leverage financing to renovate aging or neglected properties to deliver a like-new home at an attainable price point. Flipped homes accounted for 6.2% of all home sales in the U.S. in 2019, an eight-year high, according to the ATTOM Data Solutions report. Finally, investors started to thrive on the emerging peer-to-peer lending and fractional shares of the loans due to the instruments’ high interest rates compared to other investment options and short time horizons (3-18 months).
All it takes to merge these factors is an online platform, offering simple and transparent processes for all participants and access to troves of data and proprietary risk models to gain insight into the house flipping financing aspects. And the team created a lending platform that solves all the problems they experienced over the years while rehabbing houses on their own.
The platform’s defining feature is the high speed and automation of processes with much less paperwork for the customer. A customer can apply for funding in five minutes and get approval in days, not months. But first, these processes needed to be accelerated on the platform’s backend and frontend under the company’s explosive growth.
The project starts
We first met Dan Morena, the CTO, when he was looking for a team to help with the platform’s enhancement. In order to support continued growth, the five-year-old codebase, built for and by a small engineering team, would need massive refactoring and performance optimization. The second challenge was improving the platform’s scalability and speeding up engineering processes. Finally, the team was intent on delivering several significant new features. Martians joined the project to scale up the technical team to meet the goal—to resolve the main bottlenecks via refactoring, get the promising features done, and move to the entire product update. We also aimed to support new engineers onboarding and make the entire onboarding process faster and developer-friendly.
By the way, both Evil Martians and Fund That Flip were lucky to have headquarters in New York—this fact streamlined the initial stage of immersing ourselves into the business and its current challenges.
Delivering key features, ASAP
We managed to work on several key product features for the Fund That Flip platform.
Series Note Offerings
This is a fundamentally new product for the company, allowing customers to invest in a portfolio of loans with fixed rates and terms. With the traditional investment product, a lender could only lend a single borrower for a specific house flipping, choosing it from the list of those offered for investment. The new option involves investing in a special fund that selects objects for investment independently. There are two fund options—Pre-Funding Note Fund (PFNF) and Residential Bridge Note Fund (RBNF). The benefits of investing in the funds are largely similar, as both are passive investments made via a Series Note into a debt fund. One key difference is that RBNF invests in a portfolio of loans, and PFNF invests via the fund into a short-term (maximum of six months) line of credit.
This way, a lender can invest more and safer as investments are diversified and avoid focusing on just one particular project. This investing method proved more important than ever in light of the market instability caused by the COVID-19 epidemic.
Under those circumstances, it was vital to launch the feature quickly, and Martians designed a simple architecture to deliver it shortly. To date, the fund has issued more than a dozen Series Note Offerings and raised more than $13M.
Flexible annual percentage rate (APR)
Flexible APR was a part of Fund That Flip’s big architectural change to deliver a highly demanded abstract offering. This promising feature required core updates in architecture, and the company was going to move step by step on this path by a series of phased data migrations. However, a pandemic situation created a high demand for the first step—the flexible APR offer.
As shutdowns escalated quickly, the real estate rates boosted because of a surge in risks, many constructions cancellation, and flips suspension. The market immediately started to demand higher returns relative to the perceived risk. Thus, many new investors were no longer ready to invest based on the previous APR (the rates for borrowers and investors). The new feature perfectly meets their expectations to adjust rates to the market changes dynamically.
The flexible APR feature allows Fund That Flip to raise investment into an offering at any rate, independent of the underlying asset. This allowed the company to attract and convert investors while other market players were forced to press pause.
Backstage of backend refactoring
The platform required a legacy codebase refactoring to increase the app’s performance and the scaling availability and speed up the further feature development. However, refactoring a top-tier and live financial product entails an extremely sensitive approach. First, it can directly affect the customer experience and investment scenarios on the site, and second, we are dealing with financial information. Third, when you reckon with a legacy codebase, it’s inevitable to meet many exciting surprises in the code that cannot be precisely forecasted. And finally, a significant rework can be quite painful for a business since it’s time and resource-consuming while the direct business result is not immediately felt, like in situations with feature release.
Therefore, the Martians chose less severe refactoring where the critical parts of the code are improving progressively, step by step, to ensure the code predictability, stability, and maintainability. This approach also simplifies future code writing, as it has a strong basis. To frame a patһ forward, we applied an analytical approach to finding the most problematic code for refactoring by churn analysis and running Coverband, which detects the most frequently used and dead code in production.
Besides, as we had some product tasks that required heightened attention and the highest precision, after every step of refactoring, Martian engineers compared the old and the new code’s results to achieve the equal numbers that are accurate to three decimal places.
Removing the key roadblocks
We weaned the project’s codebase off of legacy “god models”—a common anti-pattern to agglomerate functionalities into a single “all-knowing” object to maintain most of the information at a single location. Splitting them into several smaller patterns helped increase the test coverage, made the codebase more maintainable, and paved the way for faster implementation of the above-described features.
Removed most of the requests based on SQL views while opting for the denormalized data structure. This sped up the execution time of a number of critical application requests from a few seconds to a few milliseconds. In addition, data design logic has become more intuitive and maintainable due to data migration from SQL to Ruby.
Fine-tuned web workers’ scaling on Heroku. We configured concurrency settings for web workers and background job workers within the production environment while fixing the database pool’s size. This facilitated background queues slack-off and averted the common issue of downtimes and slow requests caused by the lack of database connections.
We upgraded to Ruby on Rails 6 and the latest stable Ruby version.
Covering test coverage
One of the first challenges in this area was speeding up the testing processes and fully covering the platform and new releases with relevant tests.
For improvements in this area, Martians:
- Extended the current test coverage by creating tests for APIs
- Fixed and refactored existing tests
- Tuned CircleCI configurations
- Wrote system/browser tests for the “hottest” scenarios
- Optimized the compilation of assets for tests: e.g., cut them into smaller tasks and migrated assets into containers
- Used the Martian open source tool TestProf to detect and speed up the slowest tests.
As a result, we brought the test suite running time from 9 minutes down to under 3 minutes.
Solving API performance bottlenecks
The second big challenge was to fix major performance issues in the Fund That Flip API. For example, one of the API calls caused significant memory spikes, as it loaded tens of thousands of entries to Rails’ ActiveRecord. Another simple API request for getting resource data was too slow and processed for about a second even locally, while taking up to 5 seconds and about 2M Ruby object allocations on production! And there were several problems of that kind.
A bottleneck investigation inside an already running API of a large and legacy codebase is not easy. Often, simple research or even profiling may not clear things up. This inspired us to write API tests from scratch.
This helped locate the problem in return. Code reworking and a couple of Ruby gems—active-record-query-trace and Martian’s ar_lazy_preload—improved the situation while adding “memoization” to math calculations (credit score and others) solved the problem. It reduced a particular API endpoint response time from 1,000 ms to 70 ms and decreased the number of Ruby object allocations from 2M to just 50K.
Introducing new patterns to follow
The next challenge the project’s CTO assigned Martians was to gear-up feature delivery, keeping the engineering processes under control and time-boxed. Martians introduced new approaches, patterns, and tools to facilitate all the development routines and communication for the platform’s engineers. Our goal was to make the development process more efficient by writing cleaner code, using the most productive patterns and tools, and designing an architecture that is easy to maintain.
Here are examples of things Martians did to boost the team’s progress and ease the onboarding of new engineers:
Configuring and optimizing a single Docker local development environment for all services. Specifically, a Ruby on Rails monolith, two microservices, and several external services needed to be conveniently used in the local environment (sandboxes, webhooks).
Decluttering and moving all documentation to a single location while editing and adding missing docs covering the development process, QA, deploy, the incident response plan, and others.
Cross-code reviews: while the Fund That Flip team examines the Martian freshly produced code, Evil Martians review the code written by the core product and outsource project teams.
Introducing a style guide for Ruby code and enforcing it with RuboCop and CircleCI continuous integration service.
Configuring more source code linters (e.g., eslint and stylelint for styles linting) and enforcing linting via Git hooks and Martians’ own Lefthook. The newly introduced prettier formatter also helped to format the frontend code in every commit automatically via Lefthook.
In this project, Martians also worked on the frontend part of the application. The initial frontend tech stack included React, pure Redux (with no wrappers, just the library), Bootstrap + jQuery plugins, and Webpacker. Legacy frontend architecture was also in need of heavy refactoring to reduce the overall complexity, making it easier for multiple developers to work on the code.
Here’s how Martians helped enhance frontend development velocity.
Adjusting technologies to complexity profile
We’ve rewritten several critical parts of the application to use React.js—a de-facto standard for single-page applications—for its maintainability and stability.
We aimed to reduce the codebase complexity by splitting the interface to separate components —blocks that can be easily maintained and reused.
We extended Redux by Rematch wrapper to decrease the boilerplate code and make the frontend codebase more maintainable. We also added Stimulus instead of custom wrappers over jQuery plugins initialization for this purpose.
Together with the project’s backend team, Martians fixed bugs in the Rails frontend, models, and JSONAPI::Resources and returned single responsibility. We also improved JS for specific UI that needed to be isolated, properly located, and covered by tests.
To simplify the frontend development processes and make them more stable, we added generators for some React and non-React components, built as “wizards”. Generators help to keep the generated code consistency and support the code style for both engineering teams.
New frontend routines
In parallel, we spread the best engineering practices for the frontend, documented all processes, including correct file organization and naming, and automated everything we could automate.
Backend and frontend refinements fueled the speed of new features delivery. For instance, the borrower dashboard built on new technologies and new patterns was ready in just a week.
A couple of words on these features.
Lender (or Investor) dashboard lets users monitor their investments and payments history and manage both bank and platform accounts. In some way, it helped the project team to get certified to work with financial data. Martians were responsible for the UI and UX of the whole feature.
As it was an urgent task at the beginning of the cooperation, Martians used the previous tech stack (React + JSON API resources). The JSON API showed little relevance for the challenge we faced—the protocol itself has some limitations for the development process while causing many problems due to the library server part adjustment that didn’t fit the task requirements. This situation marked a turning point in the engineering process—we decided to build new features without out of place technologies.
Frontend for the new UX
One of the critical scopes was the frontend code for landing pages, borrowers, and investors’ interfaces redesign, aimed at the faster response and more convenient flow of actions. Martians reworked all the user-facing pages and improved the UX for the mobile version. Again, the component-based approach and pragmatic choice of technologies helped finish the redesign in just a month.
We also addressed the challenge of delivering a new UI smoothly. Supporting multiple redesigned features that are not yet deployed, in parallel with the rest of developments, can be exhaustive because of a big volume of changes. So, we built and deployed the reworked code in isolated “stealth” mode, not blocking the overall development process and delivering the changes iteratively. In the key moment, we switched the website to the brand new UI.
Analytics for marketing
Some product marketing problems were solved by performing a Google Analytics tracking audit for basic product analytics to configure it correctly and receive relevant data. The platform has some main events critical for the marketing team to set up advertising campaigns properly. For example, they need to track the number of registrations from the target audience after a certain campaign, deals creation, and the actual investments. We built a robust system of custom events to serve as the foundation for an extensible marketing analytics engine.
The next Martians’ crucial initiative here was to remove all the third-party trackers from the code to eliminate the additional maintenance and refine the abstract events system to automatically push all the marketing events to the Google Tag Manager layer. Marketing specialists can now configure the GTM admin dashboard accordingly, including tracking and performance monitoring in third-party systems.
Engineering for a real value
Fintech development means challenging tasks and high impact product decisions. So a serious long-term relationship matters. It was a pleasure to work with a super friendly project team that values best engineering practice and facilitated a comfortable, collaborative environment for both the core and the Martians teams.
Martians joined all the routines for better integration: we take part in daily, weekly, and biweekly team’s standups to synchronize, brainstorm, get feedback, and discuss how to improve engineering processes.
In the Fund That Flip project, we found how to refactor live financial applications with no code freeze. The updated platform’s architecture helped reduce delivery time from 2 months to 1 week for some key features. Refactoring of remaining, less critical areas is still in progress to rework all the necessary codebase parts eventually. The engineering processes fell into place, so the refactoring activities are arranged in parallel with product features launching.
Fund That Flip is continuing to increase its revenue, loan origination volume, and customer base. To date, the business provided nearly $500M in financing to hundreds of developers across the United States. On the lending side, the company has grown, expanding to hundreds of lenders who have invested in thousands of projects, and the platform boasts a repeat customer rate of 93%.
If you want Evil Martians to join and reinforce your tech team, resolve bottlenecks, and work alongside on features bringing real value to your business, please reach out to us.