The Importance of Loose Coupling in REST API Design
The Importance of Loose Coupling in REST API Design
Loose coupling is not a new concept; however, it is one that is oft neglected in the world of REST API design. Find out exactly why this is and what can be done about it.
Join the DZone community and get the full member experience.Join For Free
SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.
One of the most important ideas in the world of software engineering is the concept of loose coupling. In a loosely coupled design, components are independent, and changes in one will not affect the operation of others. This approach offers optimal flexibility and reusability when components are added, replaced, or modified. Conversely, a tightly coupled design means that components tend to be interdependent. Changes in a single component can have a system-wide impact, with unanticipated and undesirable effects.
The value of loosely coupled systems is widely recognized in the software world, but unfortunately most mobile applications end up being tightly coupled to the REST API services that they use. Each server-side API is often developed for a specific mobile application project. Each new custom application then requires another special-purpose REST API. In other words, the application and the service end up being tightly coupled to one another.
Developing a new REST API for every new project leads to backend complexity. Over time, a company can end up with infrastructure that is not portable, scalable, reliable, or secure. I have written about the problem of developing new REST APIs for every new project elsewhere, but now I think this warning should be even more strongly worded: companies should never develop a REST API for any specific application. Please read that again, it’s a game changer. You should never develop a REST API for any specific application. This practice almost always results in an application that is tightly coupled to a custom-built service.
The best approach is to build a REST API platform that can be used and reused in a flexible manner for general-purpose application development. The advantages are enormous. For example, developers don’t need to learn a new API to develop a new application. The same APIs can be reused for many different purposes. The total number of services and endpoints is consolidated, improving security. Documentation, user roles, and API services become standardized, enhancing corporate governance and compliance.
When a mobile application is developed, there is usually a server-side team that builds the REST API and a client-side team that builds the application. The interaction between these two groups takes lots of time and money while they converge on an interface. In fact, Gartner estimates that 75% of the cost of a mobile project is related to backend integration. And for this reason, the biggest benefit of a loosely coupled REST API architecture is that the interaction between these two teams is minimized.
This is where the concept of a loosely coupled REST API platform really generates business value. Components that need to “know things” about each other are tightly coupled. Components that can operate independently and have a well-defined communication channel are loosely coupled. In the same manner, if your server-side team is deeply engaged with your client-side team, then they are tightly coupled as well. These two teams can end up spending lots of time playing an expensive game of API Ping-Pong instead of shipping new applications.
As a veteran software engineer, I find one aspect of this situation rather fascinating. Usually, loose coupling is just a best practice for object-oriented software design. If you leave some tightly coupled interfaces in the code somewhere, then the worst-case scenario is probably a few snarky comments from one of the other engineers over lunch. But in this situation, there are two distinct development teams and their interaction is defined by the REST API interface they are building. Bad software design infects their working relationship, and this has real world consequences in terms of time and money.
A platform approach to RESTful services changes all of this. The server-side team focuses on mobilizing data sources, connecting legacy services, and administering role based security for the platform. The front-end team then builds anything they want on their platform of choice. Problems are minimized because the developers automatically receive the services that they need. But what type of software can actually implement a system like this?
Imagine that a modern developer could log into a portal, select the type of application that they want to build, and instantly get a comprehensive palette of REST API services designed for that purpose and vetted for use by their IT department. This is a tangible roadmap for the modern enterprise to embrace loosely coupled design and take this vision to the next level by combining secure administration with agile platform oriented application development.
The new DreamFactory Gold package provides this functionality. A company or service provider can host and manage hundreds or thousands of individual DreamFactory instances. Each one is a complete REST API development platform. Next, the administrators can define any number of pre-configured REST API packages for various purposes. Examples might include services for IoT, telephony, mobile applications, messaging, etc. These packages can include third party services like Stripe or Twilio, legacy SOAP services, and role-based access to any number of SQL or NoSQL databases. All a modern developer has to do is sign up, select a package, and start building the client application.
This is where DreamFactory is headed. For us, API automation means instantly providing a comprehensive service based environment for modern developers on demand. Use cases include exposing custom services to partners in a ready-made development environment and jump-starting enterprise developers with pre-loaded and pre-approved palettes of API services. This exciting new technology makes the benefits of loosely coupled REST API platforms a practical reality for the modern enterprise.
Published at DZone with permission of Bill Appleton , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.