Building the Lightning-Speed Ginbits APIs and apps with Lumen
Author: Kostas Papanikolaou
Building the Lightning-Speed Ginbits APIs and apps with Lumen
Building web applications is like building a house. You have countless components that are brought together to create the desired end result. Without foundations, a house cannot be built efficiently, and this applies to apps as well. At Ginbits, we have opted for one of the strongest foundations an application can have, choosing the PHP micro-framework Lumen to build our RESTful API and fast microservices that support our lightning-speed web apps.
Our constant support to the open-source community and the open-source projects that are born within it is epitomized by our choice to support our apps on the Lumen micro-framework. Thanks to its flexible nature, it can collaborate with multiple different user interface libraries and provide our front-end developers with all the information they need to build efficient UIs.
Created by Taylor Otwell, the founder of Laravel, Lumen is a fast PHP micro-framework that combines speed with flexibility and exemplifies the MVC software design pattern that Laravel follows. Lumen also provides Ginbits with the ability to take advantage of Lumen packages, pre-made, third-party libraries that contain features that can be added to any web application.
What is Lumen
Introduced in April of 2015, Lumen is an open-source project from Laravel creator Taylor Otwell. It is a web application framework that focuses heavily on speed, optimization, and is targeted at microservices. For that reason, Lumen is called a PHP “micro-framework” that allows Ginbits developers to build lightning-speed APIs and microservices.
Lumen is considered an alternative to Laravel, and our devs use it to meet the demand for lightweight installations that are faster than existing PHP micro-frameworks such as Slim and Silex. Using Lumen, Ginbits can build fast microservices as well as RESTful APIs that support fast web applications. In addition, Ginbits supports the open-source community and open-source projects such as Lumen.
What is Laravel
Also developed by Taylor Otwell, Laravel is a free, open-source PHP framework that is intended for the development of web applications. Laravel follows the model-view-controller (MVC) software design pattern. MVC is a software design pattern used by devs to create user interfaces that divided the related program logic into three elements that are interconnected.
By dividing the program logic, this design pattern separates internal representations of information from the ways information is presented to and accepted by the user. MVC is usually used for desktop graphical user interfaces (GUIs) and is quite popular for designing web applications.
Components of MVC
The MVC software design pattern consists of three main components:
- Model – The central component and the application’s dynamic data structure, independent of the user interface. It managers the data, logic, and rules of the app
- View – Any representation of information such as a diagram, table, or chart. Multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants
- Controller – Accepts input and converts it to commands for the model or view
Regarding the interactions between these three components, they are pre-defined:
- The Model manages the data of the app and receives user input from the Controller
- The View renders the presentation of the Model in a particular format
- The Controller responds to the user input and performs interactions on the data Model objects. It receives the input, can be validated (optional), and then passes it to the Model
In its foundation, the MVC software design pattern provides the “core of the solution” to an issue, and allows it to be adapted for each system.
At Ginbits we build products that are characterized by efficiency and speed. The latter is one of the main reasons why we opt for Lumen instead of Laravel. The popular PHP micro-framework is one of the fastest available worldwide. It comes with several benefits, including pre-made packages with features, clean code, the ability to build small and fast apps, a great framework for powerful APIs, and its own exciting features.
Benefits of Lumen
Being an open-source project, Lumen can collaborate with other open-source projects as well. A great example of this is Lumen packages, also known as libraries. These are third-party libraries that provide Lumen with additional functionality. They are pre-made and can be incorporated into Lumen, to provide Ginbits with much-needed features.
Packages help Ginbits and its devs to reuse some feature(s) of an application in another app. Thanks to Lumen packages, we can extract parts of an application into a package/library and add extra functionality to existing apps, focusing on a single feature or specific features.
The Clean Code Principle
Efficiency in programming is many things. Above all, it is highlighted in writing clean code. Based on the clean code principle, Lumen allows Ginbits developers to write a structured code base that is easy to read, develop, and maintain.
Guiding devs to writing clean code is one of Lumen’s most important features and one that makes this micro-framework of PHP be the top choice for us as we develop our web applications to not only be ready when they are launched but to also be consistent in the long run.
Smaller & Faster Applications
Lumen is targeted at microservices and it was created for that purpose. Microservices are small, loosely coupled components that usually support and enhance a core project. Thanks to that option, Lumen can be used to build an aspect of a Laravel application as a small, separate Lumen app. Ginbits finds great value in that option since our products receive large spikes of traffic, which can be controlled properly by a small Lumen application that is dedicated to that traffic.
Thanks to Lumen, we are able to minimize the load on our apps, and cut server costs. The latter is a reality thanks to the fact that apps built on Lumen do not require as much server power as a full Laravel application.
A strong API is the essence of every successful application. At Ginbits we opt for Lumen to build APIs that are able to support thousands of requests within seconds. With tens of simultaneous requests being handled, APIs that are built with Lumen are able to handle heavy traffic that often has large traffic spikes. That level of speed allows Ginbits to implement a RESTful API in Lumen, and build applications that have exceptional responsiveness.
Lumen utilizes the Illuminate components that power the Laravel framework. Thus, Lumen can upgrade directly to Laravel when Ginbits devs need that to happen. This might happen in case we need to take advantage of the exciting feature that Laravel has to offer, and are therefore available in Lumen.
Some features worth mentioning include:
- Routing – Provided out of the box in Lumen and includes basic routing, routing parameters, named routes, and route groups like middleware
- Authentication – Incoming requests are authenticated via stateless mechanisms such as tokens
- Caching – Cache drivers like Database, Memcached, and Redis, are supported. Our devs can install “illuminate/redis” package via Composer to use a Redis cache with Lumen
- Monolog library – Errors and Logging are implemented via the Monolog library which also provides support for various log handlers
- Queuing – A unified API is provided across a variety of different queue back-ends
- Events – A simple observer implementation allows Ginbits devs to subscribe and listen for events in our applications
- Bootstrapping – Bootstrapping processes are located in a single file
Lumen features are constantly being updated, with new ones being added as the micro-framework evolves daily, innovating the world of app building and development.
In the microservices architecture, every aspect of the application is built as a separate application, powered by its own server, and works as a stand-alone part of the bigger application. Each service is connected to its own database. A means of communication is used to help them communicate with each other. Lumen is created to work with microservices and their ability to be smaller and stand-alone is why Ginbits opts for Lumen from Laravel.
The most important word in the case of microservices architecture is “Independency”. Each service is an independent entity. They allow the scale-up of individual components, instead of the entire app.
The microservices architecture allows new developers who join Ginbits to focus on a specific service, without having to read the entire code. Each service/entity can be written in a different programming language since they use a means of communication chosen by the developer to help them communicate with each other.
Read more on Microservices in our blog “Monolithic & Microservices Architecture: A harmonized dance”