Book Image

Hands-On Swift 5 Microservices Development

Book Image

Hands-On Swift 5 Microservices Development

Overview of this book

The capabilities of the Swift programming language are extended to server-side development using popular frameworks such as Vapor. This enables Swift programmers to implement the microservices approach to design scalable and easy-to-maintain architecture for iOS, macOS, iPadOS, and watchOS applications. This book is a complete guide to building microservices for iOS applications. You’ll start by examining Swift and Vapor as backend technologies and compare them to their alternatives. The book then covers the concept of microservices to help you get started with developing your first microservice. Throughout this book, you’ll work on a case study of writing an e-commerce backend as a microservice application. You’ll understand each microservice as it is broken down into details and written out as code throughout the book. You’ll also become familiar with various aspects of server-side development such as scalability, database options, and information flow for microservices that are unwrapped in the process. As you advance, you’ll get to grips with microservices testing and see how it is different from testing a monolith application. Along the way, you’ll explore tools such as Docker, Postman, and Amazon Web Services. By the end of the book, you’ll be able to build a ready-to-deploy application that can be used as a base for future applications.
Table of Contents (19 chapters)

Who is using microservices?

After learning about the pros and cons of microservices, let's take a look at who is using them. The following examples are not exclusive and were selected with modern web applications in mind. If you want to develop an app that has the potential to become as big as Netflix, why not check out how things work well for them?

Amazon

It will probably be no surprise to learn that Amazon is one of the first big companies that utilized the internet and implemented microservices. Amazon, like many others, started out by being a big monolithic application. As it grew, additional programmers were hired and started working on the application. As you can imagine, over a hundred developers all working on the same code base will ultimately result in chaos and conflicts. This also happened in the years around 2000; so many modern tools (such as Git) were not nearly as advanced as they are today. Back then, Amazon began to break the big application up into more manageable and usable sub-units, called microservices.

Amazon is now deploying every 11.7 seconds (https://blog.newrelic.com/technology/data-culture-survey-results-faster-deployment/). Despite the challenge of having to enable hundreds of developers to work on the platform, Amazon also solved another problem: growth. Because amazon.com runs as a microservice application, it has no downtime. Amazon can take as many visitors as it gets because the system is managing itself.

By the way, Netflix, Uber, and many others are using Amazon Web Services (AWS). Amazon not only developed the concept and infrastructure for itself but is selling it to others who can use it for the same benefits.

Another noteworthy point is that Jeff Bezos has always advocated for small teams regardless of the size of the company. He claims that a team should not be larger than what two pizzas can feed (http://blog.idonethis.com/two-pizza-team/). As stated earlier, spreading the work out over to multiple people also applies to big corporations: keeping teams small increases efficiency.

Netflix

Netflix, similar to Amazon, used to be a gigantic monolithic application. And just like Amazon, Netflix split it up into many microservices to accommodate its growth. Now, Netflix is deploying thousands of times a day.

A graphical representation of its API can be found at https://www.slideshare.net/adrianco/netflix-velocity-conference-2011/43-API_AWS_EC2_Front_End

You can see how various components are working together to provide speedy delivery of content. Similar to Amazon, Netflix also had to face challenges in terms of development and growth. Using microservices allows it to address both.

Now, Netflix is serving more than 130 million accounts daily with possibly up to 400 million viewers (https://www.cheatsheet.com/entertainment/how-many-people-use-netflix.html/). These numbers should tell you how powerful a well-designed microservice architecture can be.

The bottom line is Netflix is one of the most frequently visited websites worldwide, and its approaches can teach you how to serve that many people.

Uber

Flask with Python was the basis for Uber's monolithic application. Over time, it rewrote its entire logic in smaller Python and Go services. This did not only allow Uber to optimize services according to need but also leverage the ability to use another technology for certain parts of its service. Using Go, Uber was able to increase the performance of its discovery layer.

The process of utilizing microservices well took years for Uber, and Matthew Mengerink said about fully integrating with the cloud:

"We predict it will take two years to both integrate fully with the cloud and get the platform operating thoughtfully with great tools." (https://eng.uber.com/core-infra-2018/)

Note that Uber has many thousands of employees and thousands of developers working on its infrastructure. This example should show you that it can take a long time to incorporate microservices meaningfully, even if you have a lot of engineers.

To conclude, even big companies like Uber need their due time to transition to microservices properly.

A lot of other companies

Microservices are not limited to big corporations with massive users. As you read in the list of reasons for microservices you can choose microservices even as you are just starting an application. It is often easier to start with the end in mind, rather than settling for the quicker or more expensive option in the long run.

Besides the companies listed previously, the following companies have been known to use microservices as well:

There is no clear statistic as to how many small companies are using microservices. The following list contains a few projects where I personally know the people operating them and know they are using microservices:

Most companies mentioned here are very big and serve a lot of users. Likely, you are not in a position where you face the same problems; however, you can already learn from these companies to avoid making the same mistakes. Here are the key takeaways:

  • Microservices are used across the board for companies with many users.
  • Microservices were built not only for scalability but also for internal management.
  • Microservices make a system complex.
  • Many big companies started out with a monolith but turned it into microservices.

In this section, you have seen some of the big players who use microservices and their reasons for their decisions. Don't forget that almost all of them started out as a 1-3 people company and a monolithic system. If you want your app to grow quickly and efficiently, microservices will not disappoint you. Now, let's directly compare monoliths and microservices.