microservices developers

The Advantages of Microservices in Real Estate

microservices developers

What is subletting?

First, let’s define what subletting or subleasing is. It is the activity of renting a property for the long term and dividing it into smaller units so that each unit can be rented out individually for the short term. It is widespread in densely populated cities where the cost of renting a full apartment is very expensive and most people care only about working and sleeping there. Subletting yields the maximum profit from a property. Many people here in Dubai have found either success or disaster after venturing into the business of subletting. The aim of this article is to analyze how and why these people succeeded or failed, in the context of the advantages of microservices and the disadvantages of monoliths.

Source

Does it really have anything to do with microservices?

Make no mistake, an overwhelming majority of landlords have probably never heard about the advantages of microservices. They are probably not software engineers to begin with. Perhaps the opposite is also true, that the majority of software engineers are not familiar with the subletting business. However, whether people build houses or software, there are challenges that are common to both. For starters, both are systems, in the sense that they have components that interact with each other. 

Similarly, software has modules while a subleased apartment has subtenants. Software is built to take maximum advantage of the available hardware resources, while an apartment is renovated to extract maximum rental profit. And ultimately, both require management and maintenance. Hence, the answer to the question “does this really have anything to do with microservices?” is a resounding yes. But before we get right into the advantages that microservices best practices can give to subletting, we will begin with a story very relatable to a lot of ex-pats who have come to Dubai to work.

So you want to make it big in Dubai?

You probably heard the stories even while still in your home country before you ever came to Dubai to work. The tallest building, an indoor ice mountain in the middle of the desert, artificial islands that imitate a world map and other spectacles from their benevolent Emirati rulers. Of course, you fell for it all. Now you are paying rent which amounts to from a quarter up to (God forbid) half of your salary while living in a space that is smaller than a tenth the size of what you were used to back in your home country. But you continue to soldier on.

A few months of mind conditioning, living with twenty more tenants inside an apartment is maybe not so bad after all. Then, at some point, you realize that your landlord is also an ex-pat like you. Now you are asking how he or she got to acquire the property including ten more on the other floors of the same building. You proceed to make some mental calculations based on your monthly rent and the possible number of tenants of each apartment. The numbers are in and you are shocked as to why your greedy landlord is not already in hell. You tell yourself, “at the very least the government should make this business illegal” and actually it is illegal, but better leave that topic for another article.

Source

Fast forward to when fortune finally knocks on your door. Perhaps you got lucky by getting a new job in a tech startup which pays an order of magnitude higher compared to your previous job. Perhaps an ex-pat landlord needed to return to their home country for good and offered to hand over a portion of his or her subletting empire to you for a throwaway price. Congratulations, you now have your first apartment. Being used to small spaces since you arrived in the country, instead of finding a separate place to live,  you decide to occupy just one of the partitions in the same apartment and sublet the rest. Effectively your rent is covered by the income of the other partitions being rented out. In addition, you will be able to manage your apartment “in real time” so to speak. After a year of operations you have earned so much you can acquire your second or even third apartment. Everything has been going smoothly, so you proceed to expand your business without knowing you are about to make your first big mistake.

Most businesses start as a monolith.

We mentioned “first big mistake” because you will probably commit a whole series of big mistakes before you start to realize the advantages of microservices and how it could even save you from deportation from Dubai. The root of this upcoming misfortune is that you applied the same business model that worked for you when you had just one apartment to  multiple apartments. Maybe you are not aware, but you have actually been operating within a monolithic business model, something that doesn’t scale up well. 

Let’s first describe a monolith in terms of software, so we will have a better understanding of its real world analogies. A monolith is software that is executed or terminated, deployed and released always as a single unit. The monolith may be composed of multiple components that interact with each other but each of these cannot stand alone, because  one component cannot run while another has stopped. You cannot provide more resources to one component while decreasing resources from another. The famous quote in the classic novel The Three Musketeers puts it the best, “all for one and one for all”. Now this may sound great when it comes to friendships, but in software this is a disadvantage in flexibility and maintenance. Soon you learn that the world of business is actually no different.

The disadvantages of monoliths: high coupling and low cohesion between their components

Coupling is the degree of interdependence between components. If a change in one component affects two or more components then these components are coupled. To reduce coupling we can certainly design monoliths that use interfaces between each of its components. But why bother if you intend to use all of the components as a singular unit anyway? The more details each component knows about the other components, the more efficiently they can all work together, right?

From your experience as a landlord from your first apartment, you can confirm this. While living with your tenants, you shared more than just conversations,  watched each other’s backs and solved a lot of problems that came your way. Occasional conflicts do happen,  especially when having to share a lot of stuff, but you still feel the other benefits outweigh it. You gain a false sense of wisdom that this must be the way to go for the other apartments that you will acquire too.

There is a high degree of coupling and low degree of cohesion going on here

Source

However, things haven’t gone as well as you expected. You are overwhelmed by a lot of problems fromyour other apartments. Because you are not living there, you lack the context on how to properly solve the problems  and even if you have the proper context you are not able to execute the solutions efficiently because of distance and schedule constraints.

Moreover, the tenants in the other apartments seem to be in conflict more often compared to the apartment where you are living. You did not factor in that less conflict happens in your apartment because the tenants there are conscious of your presence. In addition, because you are not going to live there you have imprudently accepted an assortment of tenants in the other apartments. Some are couples, others are single, all with  different professions and different nationalities. They are a really mixed bunch.

However, the fewer things they have in common the more difficult it is to establish a common order. In the software world, we can say that these components have low cohesion. Cohesion is the degree of togetherness of components that are functionally related to each other so much that they strongly identify within the same domain. Maintaining software with low cohesion is difficult because fixing a problem in one component does not guarantee the removal of the problem entirely because the same root cause might be found in other components.

At this point, you are probably now becoming desperate. The other apartments are giving you a lot more problems than the profit is worth, so much so that you are willing to get rid of them. Your sanity is not worth all of this, you tell yourself. But then you ask yourself, how come your previous landlord was able to handle a lot more apartments than you are able to now?

The advantages of microservices: low coupling and high cohesion between each service

It’s  because your previous landlord is following a microservices business model, that is why. He has been in the game longer than you and has probably m learned a few lessons the hard way. Your landlord knows all too well the English proverb “familiarity breeds contempt”,  so his primary concern was to reduce coupling to a minimum, especially the coupling between him and the tenants. He did this by appointing a proxy in every apartment. The proxy is also a tenant in theapartment but acts like  the API between the landlord and the other tenants. The proxy is happy to assume this responsibility for a favor such as 

reduced monthly rent. Next is to reduce coupling among the tenants themselves. He did this by removing the things that are for shared use in the apartment and if possible providing each of the tenants the same things for their private use. For instance, he got rid of the common fridge and the large dining table in the kitchen, which was a frequent source of problems, such as food items going missing or some tenants hoarding things there. Instead, he replaced it with a smaller personal fridge and table placed inside each tenant’s apartment partition. For resources that cannot be exclusively provided to each tenant, such as a washing machine, cooker or bathroom, he instructed the proxy to implement a fair rota of usage for each tenant. The less the tenants interact and share common resources, the lower the coupling.

The landlord’s next move was to increasecohesion among the tenants. An apartment that has  tenants exclusively of the same gender, the same nationality, and if possible the same professions, would mean the tenants have more in common with each other. Any issues that could arise concerning  the apartment, would probably be the same for the majority if not the same for everyone there. Hence, solving these kinds of issues would be like hitting an entire flock of birds with as few stones as possible, so to speak.

Those are the advantages of modeling your business domain properly, but there’s more…

So. You followed your ex-landlord’s advice. By lowering coupling and raising cohesion, you feel that managing your apartments is gradually becoming easier. Still, it’s no walk in the park though. But at least your operation is now sustainable and you won’t be heading to the mental asylum any time soon. But you don’t want just sustainability, you want scalability, the Amazon kind of scalability. 

Monoliths can only scale vertically up to a certain point

Source

And why not? Your ex-landlord has three times more apartments than you, and rumor has it that a certain mogul is operating a hundred apartments in the area. You ask yourself, how can they do this, when you can barely add one or two more apartments before operational challenges overwhelm you all over again. What is the missing ingredient for that special scalability recipe, you wonder. Well, according to microservices evangelist Sam Newman, it’s this:

  • Modeled Around a Business Domain
  • Automation
  • Hiding Implementation Details
  • Decentralization
  • Observability
  • Independent Deployment
  • Consumer First
  • Failure Isolation

As it turns out, there are seven more missing ingredients or principles of microservices. What you have learned and applied in your business so far, when you raised cohesion and lowered coupling, is correct Business Domain Modeling. But if you want to get more advantages from microservices architecture for your business then you shouldn’t stop there.

The advantages of microservices: Automation

Engineers make code, review code, fix code, build then finally deploy the application. This could happen several times a day, so automating the building and deploying part of it can free engineers to spend more time on  making and fixing code. Moreover, an automated build and deploy means a process less prone to human error. And your real estate business is no different. When you started with your first apartment, you were happy to do a lot of small things manually. Collecting rent from each tenant. Paying utility bills. Ordering gas cylinder refills for cooking. Calling people when some maintenance work needs doing in the apartment. For a single apartment, doing these repetitive tasks yourself is not an issue.

However, now you’ve acquired more rental property, you feel this approach is not making you happy anymore. Sometimes you even make mistakes in getting the correct amounts of rent from your tenants. This has now become a major issue. If you want your time back, you have to automate or at least semi-automate the repetitive tasks so everything is much more convenient. For example, collect cheques in advance electronically, instead of manually collecting the rents in cash.

Alternatively, you can tell your tenants to directly credit the payment to your account on or before a certain agreed date. Have an account for each apartment and set up automatic payments for the utility bills for each account. Have an agreement with the gas company to refill the cylinders when they receive orders from any tenant from your apartment. Similarly, with maintenance companies, have them do regular checkups or on-call maintenance whenever they receive a request from a tenant from any of your apartments.

The advantages of microservices: Abstracting Implementation

Microservices need to expose an API for consumers in a way that does not leak any implementation details, because for a number of reasons these are very prone to change. For instance, if the structure of the database is what drives the API, then remodeling the entities in the database when switching to a different technology – or even a simple de/normalizing to improve performance – may prove problematic once consumers already depend on these internals.

In the world of property rentals, a similar issue occurs if you renovate the apartment according to the preferences of the tenants. This situation can sink further down into dependency hell if you accept individual requests from each tenant to do any particularly unique renovations inside their apartment partitions. Some tenants would like to have a bunk bed, others a single bed, some would like to have multiple shelves on their wall, others would like to have wallpaper. Initially, this may sound like a good customer first policy, but at the end of the day, it’s actually a bad idea. Your business should depend on an API of a customer, not on details such as individual preferences. Remember that your tenants can change quite often.

There is no assurance that the next tenant will like the same renovation or would rather have it removed. Abstract your services to all your tenants in the form of a contract. The opposite is also true. Your tenants should be abstracted to you in the form of apartment rules and responsibilities that all your tenants need to follow.

The advantage of microservices: Decentralization

Microservices should be autonomous components. Each should be able to function independently, while together achieving a common goal. Having the implementation details of a microservice abstracted by an API, will already help you a lot to achieve this. Developers have more autonomy in deciding which libraries to use, which application architecture to implement, and even the entire tech stack of a microservice as long as they comply with the API. In addition, allowing each microservice to duplicate a certain amount of data from the other services helps it to continue running even when any of the other services are unavailable. Your property rental business should also take advantage of decentralization.

You already have a good start by having a proxy tenant that acts as an API between you and the other tenants in the apartment. However, don’t stop there. Give your proxy more responsibilities. Let your proxy decide on certain operational matters which involve tactical knowledge of the field in which he or she is more familiar than you. For instance, allow your proxy to find the most appropriate tenants for the apartment. Let the proxy pay the utility bills and handle maintenance issues. The proxy is your sergeant in the field and the sergeant should only report to the general later, for strategic evaluation, so to speak. The proxy is happy to do all of these things, if his or her rent is free but you will be happier because you will be  able to scale up your business without any limits.

Later on, you will end up confirming to your ex-landlord that decentralization is indeed the holy grail of property subletting.

The advantages of microservices: Observability

Microservices should be decentralized and autonomous. However, there are many instances when manual intervention is required. Or perhaps the intervention is automated but the action still comes from a source outside the microservice, regardless. In order for external actors to do this properly to a microservice, they should be observable. Logs are the primary mechanism in which services can be observed. However, relying on logs can often be too late for external actors to perform preemptive actions. Tools for monitoring and alerting at both the application and the infrastructure level are available, which could make observing microservices as easy as observing a monolithic system.

There is only one way to apply observability when you have a subletting business, and that is to install CCTV cameras! Have your cameras upload their video data onto the cloud so you can also check past events anytime through your smartphone. This will awaken your inner “Big Brother” to keep everything in check. If something has gone missing, check the cameras. Did someone break something, check the cameras. You need to settle a dispute between tenants, check the cameras. Somehow people are like quantum particles. You stabilize their state just by observing them. The cameras will also be your equalizer against the backlash of too much decentralization. If you want to give more power to your proxy tenant in the apartment, with cameras around, the chances of him or her abusing this power will drop significantly.

The advantages of microservices: Independent Deployment

Microservices should be deployable to a host without the need for other services or components to be present beforehand in the same host. Moreover, a microservice deployed in a host should not affect in any way the other services previously deployed in the same host. There are two technologies complimentary to microservices that make this possible: virtualization and containerization. Virtualization can run each microservice on its own operating system.

Host resources such as memory and CPU are still shared between multiple virtual machines but virtualization manages this allocation as efficiently as possible. In most situations, we don’t need a dedicated operating system for each microservice. We just want an environment where our microservices come with all the other dependencies it needs, as well as havingexclusive use of the latter because external services are unable to use it. Containerization is the lightweight solution for addressing this. Initially, you spend a lot of effort defining what packages are installed in the container. Or, you can rely on pre-built images and extend them with your own customizations and make this your base image across all of your microservice deployments.

After this, just run your container when you want your application and terminate the container when you are done with it. No need to think if you have installed or uninstalled and configured everything correctly every time.

In the world of apartment subletting, you can apply the same concept when you employ the services of a professional fit-out team, composed of furniture movers, maintenance people and furnishing and renovation specialists. With minimal instructions, they can carry out your designs consistently, no matter how many apartments you contract them with. Don’t have designs of your own? Not a problem, because they have designs for you to customize. It doesn’t get any more convenient than handing over the key and coming back for it later with everything in the apartment ready. They will also provide the appliances and sometimes even find you your first tenants, if you’re lucky. Of course, the services provided by the fit out team won’t be cheap. They operate similarly to a cloud Software as a Service. These guys know how to profit from your lack of virtualization and containerization expertise. But don’t get any bright ideas  about “sorting out” an apartment on your own for the sake of keeping costs down.

This process is tedious and is very difficult to get everything done right every time. If you have the money to expand, pay a professional fit-out team to “sort out” your apartment for you. If you don’t, then hire them just for consultancy, at least you can get leverage from their proven designs which you can still customize and have other teams execute cheaply. Finally, remember that if your contract for the apartment is over and you do not have plans to renew, then you need to return the unit to the real estate owner in the same mint condition as it was handed over to you. Again, the fit-out team will make sure  they undo all of the renovations in the most hassle-free way so you can claim back your  deposit.

The advantage of microservices: Consumer First

No matter how great a microservice is, it is pointless if consumers don’t know about it. There are two levels to knowing microservices. Firstly, consumers need to discover their location either through a client side or server side service registry. Remember that your microservices are deployed through containers so when containers are run on different host machines, because of scaling, the host address regularly changes. The service registry is a highly available component that is aware of these address changes. After discovering your service, the next level is to educate your consumers what wonderful things they can do with your service. API documentation tools, such as  Swagger/OpenAPI can generate a json or yaml file from your service. The consumer can view this file on a browser as a UI webpage and learn the details of a request and the response of each endpoint exposed by your service. They can even try out the endpoints from the UI webpage, if they are interested.

But back to our real estate analogy.Any apartment subletting mogul realizes that by partitioning an apartment the effort of filling it up with tenants significantly becomes more difficult. The trick is not to try to find the tenants, instead you let the tenants find you. Likewise, there are two levels to this approach. Firstly, you can advertise through AirBnB or some other similar website. The next level is to have agents that actively search for tenants for you for a commission on every tenant they successfully bring in. Send some good pictures of the apartment to the agent, particularly for each partition, and of course the rental prices. Finally, give them the keys to your apartments so they can effectively do the marketing on your place. Entertaining prospective tenants can often be frustrating. Even if you schedule a meeting with them, there is a good chance they will cancel at the last minute. Moreover, after having spent effort on meetings and showing them the apartment they lose interest at the end. Let your agents handle this frustration.

The advantages of microservices: Failure Isolation

Maybe one of the microservices started receiving a huge volume of requests it could not handle. Maybe the power failed on one of the host machines. Maybe the network got disconnected. In the real world, failure is not a matter of “if” but “when”. In microservices architecture, failure isolation means the application is running in a degraded state but the majority of its functions still work. This is achieved using several techniques. The easiest is timeout tuning. The overloaded microservice is still alive but probably won’t respond in a manner acceptable to consumers.

The only thing worse than a failed response is a slow failed response. Hence, tuning down the timeout threshold from a minute to a few seconds will enable the consumers to receive a faster failure so they can be doing something else in the application. An extension of this technique is short circuiting the request. Basically, if the request calls another microservice which is currently misbehaving, the circuit is opened at the API layer but will automatically close back after a certain duration of time. While the circuit is open, requests immediately fail without going through the service calls, giving time for the misbehaving service to heal.

Finally, failure isolation can work the other way around. Instead of keeping the requests to go to the failing component, the failing component can contain the problem within itself, without affecting others, through a bulkheading technique. A bulkhead is usually a compartment for resources that may be used up, so that other components of the system won’t have their resources affected.

Now for the interesting part, what are the common failures in a subletting business? Tenants unable to pay their rent is the most common failure. Fortunately, if the apartment is renovated, so it now has multiple partition apartments, then you  already have a type of bulkheading. If one or two tenants suddenly leave or fail to pay and have used up their deposits, replacing them is easy. Even if one or two partitions are empty for a couple of months, the loss will not be that great since the other partitions will continue to bring in income. Next, make sure you decrease your timeout threshold for failures to pay rent. Don’t wait for a tenant who is unable to pay for three consecutive months, because they promised to settle all of their unpaid rent the next month. Just give them one week to settle, and if they don’t, then evict them without mercy.

But what about an extreme scenario, what if all your tenants are unable to pay rent? The chances of this happening increases if all of your tenants are working for the same company. If that company closes for some reason (another pandemic crisis perhaps?) then your business will be in a very challenging situation because even if all of your tenants do not pay their rent, you will still need to pay rent for the whole apartment, not to mention the monthly utilities. Remember that you are bound to a yearly contract with the real estate company, so they can always come after you if you don’t pay for the whole duration of the contract. There are two ways out of this extreme situation. One is to negotiate for contract cancellation. The real estate agency will charge you a couple of months of advance rent but at least you won’t be buried in debts. The faster you cut your losses, the faster you can start to recover. The other option is to have prepared for this situation, right from the beginning. Don’t enter into the contract with the real estate yourself. Rather pay your proxy tenant or someone else to get involved with the real estate company instead of you.

Final Thoughts

Subletting in Dubai is a lucrative but crazy business. I personally wouldn’t recommend it for the faint of heart. A few landlords may have unintentionally discovered microservices best practices, which have enabled them to scale up their business to unbelievable proportions. Not all are blessed with such insights though. The majority are not aware of the advantages of microservice principles, as they continue to expand their subletting operations until they reach a crawl. Because it is very easy to get a loan from banks in Dubai, some naive investors could keep acquiring more apartments while still following a monolithic business practice. Eventually, these operations will incur more losses than profits, and when the repayments on the bank loans aren’t made, they will soon be serving jail time, as financial debt is a crime in Dubai.

Fancy a free ride in a supercar? Try not paying the banks.

Source

Download e-book:

Scalac Case Study Book

Download now

Authors

Ornel Lloyd Edano
Ornel Lloyd Edano

Currently a Scala Developer, former Java Developer and former Game Developer. I like to learn and do many things that I find interesting outside programming.

Latest Blogposts

23.04.2024 / By  Bartosz Budnik

Kalix tutorial: Building invoice application

Kalix app building.

Scala is well-known for its great functional scala libraries which enable the building of complex applications designed for streaming data or providing reliable solutions with effect systems. However, there are not that many solutions which we could call frameworks to provide every necessary tool and out-of-the box integrations with databases, message brokers, etc. In 2022, Kalix was […]

17.04.2024 / By  Michał Szajkowski

Mocking Libraries can be your doom

Test Automations

Test automation is great. Nowadays, it’s become a crucial part of basically any software development process. And at the unit test level it is often a necessity to mimic a foreign service or other dependencies you want to isolate from. So in such a case, using a mock library should be an obvious choice that […]

04.04.2024 / By  Aleksander Rainko

Scala 3 Data Transformation Library: ducktape 0.2.0.

Scala 3 Data Transformation Library: Ducktape 2.0

Introduction: Is ducktape still all duct tape under the hood? Or, why are macros so cool that I’m basically rewriting it for the third time? Before I go off talking about the insides of the library, let’s first touch base on what ducktape actually is, its Github page describes it as this: Automatic and customizable […]

software product development

Need a successful project?

Estimate project