top of page
Writer's pictureDavid McGinnis

Abstracting External Services with I/O Interfaces - Part 1

Updated: Feb 2, 2022

While this is a concept I've used at many clients, I've never seen this concept approached elsewhere. Because of this, all of the terminology used in this post is mine. I would love to find more official or accepted terminology for these ideas or a more accepted version of this pattern if anyone has come across them!


Background

Whenever a non-trivial system is architected, there will be at least one external system which you rely on. This might be a file system, a database, a notification service, or any number of other services. Oftentimes, the system doesn't need to deal with the inner workings of the service, nor does it depend on a particular service. Instead, the system just relies on the general contours of the service.


For example, a microservices architecture generally will not care if you are using Kinesis or Kafka or some other more esoteric system as your messaging service. At the code level, it may not even care if you are using a queuing system like RabbitMQ or an event notification service like SNS, even though these have major differences between them. We could say similar things for file stores, key-value databases, RDBMS systems, notification systems (such as email, slack messages, etc.), and many others.


Abstracting and Swapping

Using this idea, we can see how we could create a generalized interface for each of these, which I call an I/O Interface. These interfaces will have one or more implementations for a given system that can be swapped between each other easily depending on anything from what environment we are running in to what a configuration file tells us to what time of day it is. This allows nearly the entire system to be agnostic to the platform we are running on, while still interacting with that platform. Each implementation is called an Implementation or a Service.


Finally, these Implementations can be grouped together into services that work together to make it easier to pass them throughout the system. You can almost think of this as a distribution (i.e., Hadoop Distribution or Linux Distribution), with a set of Implementations known to work well together grouped together for specific use cases. These groupings are called Environments. So, you might have a production environment, a test environment, etc. Then you can just pass this Environment instance around the system and a function that needs to interact with the outside world can access the Environment to get what it needs without changing any interfaces.


But... Why?

Just because we can do this doesn't mean we should, however. But there are a few good reasons to abstract away the exact service, especially when it comes to data and cloud centric systems.


The first is to allow easier testing. If I build a system that reads messages from Kinesis, enriches the messages with data from DynamoDB, and then outputs a message to Slack with the results, writing unit tests may be easy enough, but writing higher-level tests that do not have to use AWS or Slack is tricky without some abstraction. Creating I/O Interfaces for message services, operational datastore, and notification service allows the majority of the system to be tested using one set of implementations that mocks out everything. We then just need to implement the actual I/O Interfaces to use in the production system and have a smaller set of tests that test that functionality locally. This restricts the scope of the sometimes-finicky process of mocking out these complex libraries like boto3 or requests. This doesn't resolve you of the need to do end-to-end tests on AWS itself, but it does make more of your tests simpler, which is always a good goal for maintainability.


Another reason this can be appealing is when you're building with services that may be changed by business decisions later, whether wholesale or bit-by-bit. The obvious example here is the business decides they want to use a different platform, such as Azure instead of AWS. In the example above, that just requires writing new IO Interfaces for Azure Pub/Sub and CosmosDB, and testing those, and maybe tweaking the function definition for the entry points. We can even do this while we are still using AWS in production, allowing us to build side-by-side for a while. Without this abstraction, assumptions about the platform can spread throughout the code base and building side-by-side as other dependencies are completed around you is near impossible.


While switching from one cloud to another may not happen all that often, smaller changes happen with some regularity. As an example, at a client of mine, we had a system which uploaded reports to S3 for business users. After some time, it was determined that using object URLs was not secure enough, and the workflow for business users to read reports from S3 without this was too unwieldy. Because of that, it was requested the reports instead be uploaded to Sharepoint for use, where things like SSO could be used directly. Without an approach like I/O Interfaces, we would've needed to scour the system for any assumptions we were making that we were sending reports to S3. This may have included code where we were building S3 paths or calling boto3 functions directly for small one-off operations like fixing permissions. Instead, we could just write a new I/O Interface for Sharepoint with the same interface (one specifically for file storage) and use that in this instance. Once tests were written for that I/O interface, everything was ready to go in much less time. The S3 I/O interface could even still be used to upload more technical files that we were fine requiring the user to log into AWS for.


A final reason I've seen is if different executions using the same code base have different packages available. For example, if we are building a microservices architecture, each Lambda function might use the same code base, with a different entry point. Each function may need different dependencies, but since we are using a shared code base, it makes sense to share those dependencies when possible.


One Lambda function, though, may have a certain dependency that the others don't and can cause problems if included on all functions. We can use layers to ensure just that one Lambda function has the dependency, but we need to make sure the other functions aren't including that dependency accidentally through an import. This is where having separate Environments come into play, since you can have two production Environments, one with the dependency and one without. The functions pick the ones they need, and the other is never executed, so no problematic dependencies are included.


Conclusion

This finishes up the concept of why something like I/O interfaces might be useful and how we can use them. Next week, we'll be diving into the technical details and also discussing the architectural design patterns at play here. Stay tuned!

203 views1 comment

Recent Posts

See All

1 Comment


jovankagrace
Mar 13, 2023

Rley Site

https://www.marleys.net/profile/demonslayer2023/profile

https://www.lifedecisions.net/profile/demonslayer2023/profile

https://www.transformativereading.net/profile/demonslayer2023/profile

https://www.sagenselenite.net/profile/demonslayer2023/profile

https://www.capriwindow.net/profile/demonslayer2023/profile

https://www.beauteouslife.net/profile-1/demonslayer2023/profile

https://www.debhart.net/profile/demonslayer2023/profile

https://www.doublegcattle.net/profile/demonslayer2023/profile

https://www.kfpconsulting.net/profile/demonslayer2023/profile

https://www.readysetquilt.net/profile/demonslayer2023/profile

https://www.liveandamplified.net/profile/demonslayer2023/profile

https://www.pwcoaching.net/profile/demonslayer2023/profile

https://www.rev310.net/profile/demonslayer2023/profile

https://www.naiomiglasses.net/profile/demonslayer2023/profile

https://www.ghtexas.net/profile/demonslayer2023/profile

https://www.urbanecoevo.net/profile/demonslayer2023/profile

https://www.remdc.net/profile/demonslayer2023/profile

https://www.ynpnchicago.org/profile/demonslayer2023/profile

https://watchfullshazamfuryofthegods2023moviefullhd.wordpress.com/

https://en.gravatar.com/edreachloe

https://www.expat.com/forum/profile.php?id=1200301

https://www.cheftalk.com/members/edreachloe.121291/

https://app.joinhandshake.com/stu/users/48176464

https://www.cairnguides.com/profile/edreachloe/profile

https://angel.co/u/watch-full-shazam-fury-of-the-gods-2023-movie-full-hd-bluray

https://unsplash.com/@shazamfuryofthegods2023

https://influence.co/shazamfuryofthegods2023

https://shazamfuryofthegods2023.carrd.co/

https://en.infinitykey.rocks/profile/edreachloe/profile

https://www.martinicoffee.com/profile/shazamfuryofthegods2023/profile

https://www.theathleticroom.com/profile/shazamfuryofthegods2023/profile

https://www.suprance.com/profile/shazamfuryofthegods2023/profile

https://www.metimetherapy.org/profile/shazamfuryofthegods2023/profile

https://www.jami-leephotography.com/profile/shazamfuryofthegods2023/profile

https://www.atpperformancellc.com/profile/shazamfuryofthegods2023/profile

https://jinenya.wixsite.com/jinenyadrink/profile/shazamfuryofthegods2023/profile

https://www.wostudios.co/profile/shazamfuryofthegods2023/profile

https://www.floraldevine.com.au/profile/edreachloe/profile

https://www.datamars.co.uk/profile/shazamfuryofthegods2023/profile

https://www.bethelchristianassembly-church.com/profile/shazamfuryofthegods2023/profile

https://www.zidouri.com/profile/shazamfuryofthegods2023/profile

https://www.caboblue.net/profile/shazamfuryofthegods2023/profile

https://axizcesdiaroro.wixsite.com/searlouihotnheart/profile/shazamfuryofthegods2023/profile

https://www.astra-photography.co.uk/profile/shazamfuryofthegods2023/profile

https://www.ladaskamanufacturing.com/profile/shazamfuryofthegods2023/profile

https://www.livingstronghealingcentre.com/profile/shazamfuryofthegods2023/profile

https://www.kirbysnelldance.com/profile/shazamfuryofthegods2023/profile

https://www.lezzgolearnin.com/profile/shazamfuryofthegods2023/profile

https://astronomyhubcluj.wixsite.com/astro/profile/shazamfuryofthegods2023/profile

https://www.charityrunmalta.com/profile/shazamfuryofthegods2023/profile

https://www.outofthecave.health/profile/shazamfuryofthegods2023/profile

https://www.riverdaleheightspta.com/profile/edreachloe/profile

https://www.t1dacademy.ca/profile/shazamfuryofthegods2023/profile

https://www.centeryourbodypilates.com/profile/shazamfuryofthegods2023/profile

https://hi.kfimmigrationcanada.ca/profile/shazamfuryofthegods2023/profile

https://www.caffedarte.com/profile/shazamfuryofthegods2023/profile

https://www.averagejoesjoinery.com/profile/shazamfuryofthegods2023/profile

https://www.onedishwonderful.com/profile/shazamfuryofthegods2023/profile

https://www.hummingbirds.cc/profile/shazamfuryofthegods2023/profile

https://www.smithtownfd.org/profile/shazamfuryofthegods2023/profile

https://www.wellrounded.health/profile/shazamfuryofthegods2023/profile

https://www.blindedbythefloodlights.com/profile/shazamfuryofthegods2023/profile

https://www.occasionalcreches.com/profile/shazamfuryofthegods2023/profile

https://www.pistardsengex.com/profile/shazamfuryofthegods2023/profile

https://synergia5c.wixsite.com/ventas/profile/shazamfuryofthegods2023/profile

https://www.makeupmasters.ie/profile/shazamfuryofthegods2023/profile

https://www.finanzasyriqueza.info/profile/shazamfuryofthegods2023/profile

https://www.rodsroadsideservice.com/profile/shazamfuryofthegods2023/profile?lang=ko

https://www.chulavistacc.org/profile/shazamfuryofthegods2023/profile

https://www.surfin.es/profile/shazamfuryofthegods2023/profile

https://www.westmountfitness.com/profile/shazamfuryofthegods2023/profile

https://www.martinedocourt.ch/profile/shazamfuryofthegods2023/profile

https://nicolasterre.wixsite.com/education-physique/profile/shazamfuryofthegods2023/profile

https://www.sharonhomecooking.com/profile/shazamfuryofthegods2023/profile

https://www.super2bit.com/profile/shazamfuryofthegods2023/profile

https://www.jeffersongrange1384pa.org/profile/shazamfuryofthegods2023/profile

https://www.healthynutritiongists.com/profile/shazamfuryofthegods2023/profile

https://www.sammycooks.net/profile/shazamfuryofthegods2023/profile

https://issuu.com/watchfullshazamfuryofthegods2023

https://www.nonstampcollecting.com/profile/shazamfuryofthegods2023/profile

https://www.veraley.com/profile/shazamfuryofthegods2023/profile

https://www.michaelpanneau-naturopathe.com/profile/shazamfuryofthegods2023/profile

https://www.twirlingbaton-plandegrasse.com/profile/shazamfuryofthegods2023/profile

https://www.thousandhills.gr/profile/shazamfuryofthegods2023/profile

https://www.israel-2030.org/profile/shazamfuryofthegods2023/profile

https://www.bootledanceacademy.com/profile/shazamfuryofthegods2023/profile

https://en.abouttime-tech.com/profile/shazamfuryofthegods2023/profile

https://www.lancashirevetphysio.co.uk/profile/shazamfuryofthegods2023/profile

https://www.shustringmagazine.com/profile/shazamfuryofthegods2023/profile

https://www.emprendedorforestal.org/profile/shazamfuryofthegods2023/profile

https://www.dnfconline.org/profile/shazamfuryofthegods2023/profile

https://bh.canyonhillsptsa.com/profile/shazamfuryofthegods2023/profile

https://www.qasaqasa.co.uk/profile/shazamfuryofthegods2023/profile

https://www.flyingfaith.org/account/my-account

https://www.rootedoakchurch.org/profile/shazamfuryofthegods2023/profile

https://www.gerkensorganics.com/profile/shazamfuryofthegods2023/profile

https://www.josefzezulka.cz/profile/shazamfuryofthegods2023/profile

https://www.nationaldvcollaborative.org/profile/shazamfuryofthegods2023/profile

https://ko-fi.com/shazamfuryofthegods2023

https://www.cakeresume.com/me/shazamfuryofthegods2023

https://www.cakeresume.com/me/shazamfuryofthegods2023/portfolios?ref=navs_portfolio

https://www.cakeresume.com/portfolios/watch-full-shazam-fury-of-the-gods-2023

https://wakelet.com/@watchshazamfuryofthegods2023

https://melaninterest.com/user/shazamfuryofthegods2023/

https://melaninterest.com/pin/watch-full-shazam-fury-of-the-gods-2023-movie-full-hd/

https://www.oteopalebeauty.com/profile/shazamfuryofthegods2023/profile

https://www.empoweryouroils.com/profile/shazamfuryofthegods2023/profile

https://lightthetorch.wixsite.com/website/profile/shazamfuryofthegods2023/profile

https://www.emeralddocument.com/profile/shazamfuryofthegods2023/profile

https://www.ten20words.com/profile/shazamfuryofthegods2023/profile

https://www.ktoolmart.com/profile/shazamfuryofthegods2023/profile

https://en.wpa.pt/profile/edreachloe/profile

https://www.thestreet-angels.org/profile/shazamfuryofthegods2023/profile

https://www.fia.ge/profile/shazamfuryofthegods2023/profile

https://www.henscrossing.com/profile/shazamfuryofthegods2023/profile

https://www.jenhealthandwellness.com/profile/shazamfuryofthegods2023/profile

https://www.hannahleeart.com/profile/shazamfuryofthegods2023/profile

Like
  • Twitter Social Icon
  • LinkedIn Social Icon
bottom of page