Microservices Architecture: Development with Lumen (Laravel) Microframework
«Microservices» or «microservice architectural style» is an approach to developing a single application as a suite of small parts – services accessed through APIs - as opposed to «monolithic architectural style» when an application is built as a single unit. It allows different microservices to be written in different programming languages, and they can also be managed by different teams. When is it a good idea to use this architecture in custom software development and why do we use Lumen to build microservices?
WHEN IT IS A GOOD IDEA TO USE MICROSERVICES
According to the software requirements, each web project is reduced to one of the following types:
- Development of an application from scratch;
- Rebuilding (or refactoring) a legacy application;
- Adding new functionality to an existing application.
Microservices architectural approach can be used in each of these cases. But often it is used for refactoring (rewriting) a legacy application from monolith into microservices.
Basically, there are 4 main reasons for it:
- The application is getting so big that developers need a lot of time to understand it, and therefore organizational/project scaling issues are arising;
- The application consists of different parts with independent and very different update&release frequencies;
- There is a necessity to dynamically scale specific parts of the system up and down, independently from the other parts;
- Different parts of the system have specific domain or technical requirements that force developers to use a programming language/framework which is different than the common programming language of the team.
BUSINESS PERSPECTIVES OF MICROSERVICE ARCHITECTURE
- Protect from failure. In a monolithic service, if the service fails, everything stops working. With a monolithic system, we can run on multiple machines to reduce our chances of failure, but with microservices, we can build systems that can handle the total failure of services. Since services can fail at any time, it's important to be able to detect the issue quickly and, if possible, automatically restore working order. Microservice applications put a lot of emphasis on real-time monitoring, checking both architectural elements (how many requests per second is the database getting) and business-relevant metrics (such as how many orders per minute are received). Semantic monitoring can provide an early warning system of something going wrong that triggers development teams to follow up and investigate. This is one of the main reasons why organizations like Amazon and Netflix use these architectures—to ensure they remove as many impediments to getting software out the door as possible.
- Scalability. A change made to a small part of the monolithic application (scaling), requires scaling of the entire application rather than parts of it which in turn requires greater resources (hidden costs of building the monolithic application). In contrast, microservices are independently scalable. With microservices, developers can make a change to a single service and deploy it (moving from test server to production server) independently of the rest of the system.
- Decreasing team size and their productivity. Microservices help developers minimize the number of people working on each codebase to hit the sweet spot of team size and productivity. Project managers can also shift ownership of services between teams to keep people working on one service collocated. When services are isolated from each other, much less coordination is needed between service owners. The less coordination needed between teams, the more autonomy those teams have, as they are able to operate and evolve their services more freely.
EXAMPLES OF PROJECTS WITH MICROSERVICES ARCHITECTURE
- Gilt, an online fashion retailer, started in 2007 as a monolithic application, but by 2009 Gilt’s system was unable to cope with the load being placed on it. By splitting out core parts of its system, Gilt was able to better deal with its traffic spikes, and today has over 450 microservices, each running on a separate machine.
- The Guardian website is another example of an application that was designed and built as a monolith, but has been evolving in a microservice direction. The monolith still is the core of the website, but they prefer to add new features by building microservices that use the monolith's API. This approach is particularly handy for features that are inherently temporary, such as specialized pages to handle a sporting event. Such a part of the website can quickly be put together using rapid development languages, and removed once the event is over. Similar approaches are used at a financial institution where new services are added for a market opportunity and discarded after a few months or even weeks.
- Other examples include Amazon, Netflix, Google, Ebay, the UK Government Digital Service, realestate.com.au, Soundcloud, Forward, and comparethemarket.com.
WHY WE USE LUMEN IN BUILDING MICROSERVICES
Microservices need to possess the ability to read and write to a database, must be secured, be built with the so-called message-driven approach, and have the ability to provide reports. Modern microframeworks make these tasks as trivial as possible.
Lumen is the perfect solution for building microservices. It utilizes all benefits of Laravel framework including security, easy database configuration (MySQL, Postgres, SQLite, and SQL Server), queue service configuration, integration with reporting tools and so on.
LUMEN MICROSERVICES ARCHITECTURE EXAMPLE
Let’s imagine a standard web page on an ecommerce website. To pull together the various parts of that website, we might need several microservices. One of them might display the details about the product being offered for sale. Another might show the price and stock level. And we’ll probably be showing shopping cart contents too, which may be another microservice.
If the shopping cart service is unavailable, we’re probably in a lot of trouble, but we could still show the web page with the listing. Perhaps we just hide the shopping cart or replace it with an icon saying “Will Be Back Soon!” or replace the part of the UI containing the cart control with a phone number for placing an order.
The most popular open source microservices created using Lumen are located on github.com.
RESTful API Development with Lumen (Laravel) Microframework
API is an approach that allows different applications or different parts of a single application to share data among each other by special programming commands. By default, an application has no use for APIs if it is not defined by software requirements. When a customer orders an API creation from us and they want to go with Laravel Development then we usually suggest the use of Lumen. When is it necessary to develop an API for the application and why do we choose Lumen for this?
Example of using API
Probably every internet user has seen the most commonly known example of using API: the interactive Google Map in the 'Contact Us' section of almost any website. Each time a website displays this map, it sends a request across the Internet to a special APIs that’s offered by Google for that very purpose and it then receives the appropriate data transformed into an interactive Google Map. It means there is no necessity to redevelop Google Maps in order to add that functionality to the website (cost-effective approach) because it can be simply used by integrating the needed functionality through APIs.
Business perspectives of API development
As ProgrammableWeb editor-in-chief, David Berlind puts in his blog:
“For those who understand the potential of APIs, there could be millions of dollars to be made, or saved”.
Google Maps is an example of a cloud based web application that shares its own functionality through APIs for free, but with some limits, after exceeding which this API functionality becomes paid. Some other great companies such as Ebay provide APIs that help entrepreneurs to make money by integrating their web, desktop or mobile applications with the eBay API platform.
Lumen API development examples
For any API service, speed is very important, because if it is not able to serve a lot of requests per second fast, the business perspectives of using the API will be much reduced.
As we considered earlier, API development can be done using fast microframeworks like Lumen, which is one of the fastest PHP micro-frameworks available.
- Lumen microframework can be used to build an API for a web application to integrate it with a mobile application. Simple example: a mobile bookstore application offers a search feature, where the user can look for books by author name. The mobile application needs to use an API, which should be provided by a bookstore web service, to get data about authors and books.
- Lumen microframework can be used to build an API for integrating different microservices within a large service/application (core project). For example, a core web application helps to order stuff from local, offline stores/partners. Each of these stores/services come with their own APIs. The right development approach is to create a microservice, which will call the APIs of the partners and provide its own API to transfer data received from partners to the core web application.
The most popular open source APIs created using Lumen are located on github.com.
Articles you might be interested in: