Writing Testable Serverless Apps Using Hexagonal Architecture

Rate this content
Bookmark

According to many polls, testing serverless applications and fear of the cloud vendor lock-in are among the top five challenges organizations face when adopting serverless. We often hear that using serverless effectively requires a mind shift. But what does that mean? Do we need new tools and strategies for testing serverless applications, or can we use existing tools we already use for our non-serverless applications? And what about cloud vendor lock-in? Is that a real thing or just a fictional story that scares people away from serverless? Can we decrease a risk of vendor lock-in using a well-known architecture, such as hexagonal architecture?

FAQ

Vendor lock-in in economics makes a customer dependent on a vendor for products or services, making it costly to switch to another vendor without incurring substantial switching costs.

To mitigate vendor lock-in, consider planning and analyzing potential future needs and switching costs, maintaining a flexible architecture, and ensuring that deployment procedures are in place to facilitate easier migration if needed.

Hexagonal architecture, also known as ports and adapters architecture, allows an application to be driven by different inputs and outputs such as users, programs, or tests, and be developed and tested in isolation from external systems like databases.

Testing is crucial for serverless applications because while the infrastructure is managed by the vendor, the business logic and code integration need to be maintained and tested by the developers to ensure they function correctly and efficiently.

Hexagonal architecture helps in isolating business logic from external influences, making serverless applications easier to test and more adaptable to changes in external services or platforms, thereby helping in managing switching costs and preventing vendor lock-in.

AWS SAM (Serverless Application Model) helps in deploying serverless applications and can also run parts of the application locally, which is useful for testing and ensuring the application functions correctly before deployment.

Slobodan Stojanović
Slobodan Stojanović
28 min
15 Jun, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The scariest thing about serverless is the fear of vendor lock-in and losing control. Planning, good architecture, and deployment procedures help keep switching costs reasonable. Hexagonal architecture is a useful approach for writing testable serverless apps. Integration testing is crucial for serverless apps, and hexagonal architecture helps fight vendor lock-in and reduce switching costs. Docker is used for testing serverless functions, and the practicality of hexagonal architecture remains a question.

1. The Scariest Thing About Serverless

Short description:

The scariest thing about serverless is losing control and the fear of vendor lock-in. Vendor lock-in refers to being dependent on a specific vendor for products or services, making it difficult to switch to another vendor without significant costs. Let's explain this with a server rental analogy. You rent a server from a guy named Jeff, who provides additional services like databases and caching. However, if Jeff increases the prices or becomes unreliable, you have the option to switch to another provider like Bill. But migrating your application to a different provider can be time-consuming and costly. This is what we call cloud vendor lock-in.

Hello. What's the scariest thing about serverless? There are many scary things, right? Well, some people would say that the scariest thing is long-running tasks, but that's not really the scariest thing because there are many ways to have longer-running functions and things like this. Have you heard about cold start? That was a really scary thing at the beginning, but now it's not that much because with Node.js, your cold start is maybe 100 milliseconds or something like that.

What about local development and debugging? That's still really hard thing to do but tooling is getting better every day so it's not really that scary anymore. But there's one thing that everyone is mentioning, it's losing control. Yeah, maybe, but on the other side, with losing control, you're gaining speed and some other things. So I don't think that's the scariest thing. But again, there's one thing that everyone is scared about and it doesn't matter if you talk to developer or some business person, everyone will mention big bad vendor lock-in. It's really scary, right?

But let's see what's vendor lock-in. If you go to Wikipedia, you'll see that in economics, vendor lock-in makes a customer dependent on a vendor for products or services unable to use another vendor without substantial switching costs. I don't really like the definition so let's try to explain with a few diagrams. So let's say that you need a server. I don't know why, but you just want to have a server and build some kind of application. You can buy it or rent it, but no one is buying servers anymore. So you decide to rent it. You find a guy that has a lot of servers in his basement, let's call that guy Jeff, and you rent one server from Jeff and that's now your cloud. You're using that server and after some time, Jeff is really smart and he knows how to use his servers and he knows that you're building databases, some caching and things like this. So he starts building services for you. You can use just a database without the server or just use cache or maybe machine learning or functions. And it's even better because you can pay for these things only when you use them. It's really awesome and he will love your cloud services now. But what if Jeff is actually a villain and at some point you're so dependent that he'd services and he increased costs of all of these services. And of course your wallet would not be happy in this moment and you will not be happy for sure. But fortunately you have some options. For example, you can find another guy that has a lot of servers in his basement or whatever, let's call this one Bill And Bill also has a database and compute and machine learning and everything else. And the costs are more or less the same as the cost of Jeff's services before he increased the pricing. But what's expensive is migration because Jeff's database is not exactly the same as Bill's database. So you need to invest a lot of time to move your application from one services to other. And that's basically cloud vendor lock in. We saw another example lately with Parler, but that's likely different because they're not able to migrate to any big vendor.

2. Switching Costs and Testable Serverless Apps

Short description:

Vendor lock-in refers to switching costs when changing platforms or vendors. Planning, good architecture, and deployment procedures help keep switching costs reasonable. Today's topic is writing testable serverless apps using hexagonal architecture. Testing is important for serverless apps as you still own your code and business logic. Serverless apps often have small services with external dependencies. For example, our WebApp with a Slack chatbot allows users to request vacation with a few clicks.

So this is really extreme case, but this presentation will not cover that. Regarding vendor lock-in, I really think that Mark Schwartz, enterprise strategist at AWS is right. He thinks that term lock-in is misleading because we're actually talking about switching costs. As soon as we commit to any platform or a vendor, we'll have switching costs if we later decide to change that vendor or platform. For example, if you build your application in PHP, and then at some point you want to migrate that to Node.js or Go or something else, you'll have a big switching cost because you need to pause for some time, rebuild everything in a different language, and then continue from that point.

So, how do we fight vendor lock-in, or let's ask the better question, how do we keep our switching costs reasonable? Well, we can do a few things. First, we need to do planning and analysis. For example, we need to answer some questions such as how likely will I need to switch to another platform or service? What would be the cost for that switch? If there is no big chance to switch to something else, for example, you picked your database and you don't think you will need to switch in the near future, it's okay to have a slightly higher cost of migration, but for some other things, you need to keep that cost lower. You need to have a good architecture, of course. And finally, you need to have deployment procedures because if you don't have them, it will be really, really hard to migrate anywhere.

That leads us to our topic for today, and that's writing testable serverless applications and preventing vendor lock-in using hexagonal architecture. But before we continue, let me introduce myself. I'm Slobodan Stanovich, I'm CTO and partner at Cloud Horizon and VacationTracker, VacationTracker is a lead tracking management system and Cloud Horizon is basically an agency we are doing web apps for other people. I also wrote the book, Serverless Applications with Node.js with my friend Alexander Simovich, and it's published by many publications. And I'm also AWS serverless hero. You can follow me on my website. I write about serverless a lot and testing also. So let's go back to our topic because that's definitely more interesting than I am. So we'll talk about writing testable serverless apps using hexagonal architecture. But let's focus on testable part first. Why is testing important for serverless apps? You basically outsource some parts of your app to a vendor, but that's not covering everything. They'll manage infrastructure for you, but you still own your code and your business logic. So you need to test that part of the application. And also most of the time serverless applications are not fully isolated monoliths without integrations. Instead, there contain a lot of small services that are interacting with each other all the time, and they have a lot of external dependencies. I mentioned vacation tracker, so here's an example. Our application is WebApp that has also Slack chatbot. And inside Slack, you can type slash vacation and request vacation in just a few clicks. It's so easy, you can do that in just a few minutes, actually a few seconds. But in the background, that looks something like this.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
Do you have a large product built by many teams? Are you struggling to release often? Did your frontend turn into a massive unmaintainable monolith? If, like me, you’ve answered yes to any of those questions, this talk is for you! I’ll show you exactly how you can build a micro frontend architecture with Remix to solve those challenges.
Network Requests with Cypress
TestJS Summit 2021TestJS Summit 2021
33 min
Network Requests with Cypress
Top Content
Whether you're testing your UI or API, Cypress gives you all the tools needed to work with and manage network requests. This intermediate-level task demonstrates how to use the cy.request and cy.intercept commands to execute, spy on, and stub network requests while testing your application in the browser. Learn how the commands work as well as use cases for each, including best practices for testing and mocking your network requests.
Testing Pyramid Makes Little Sense, What We Can Use Instead
TestJS Summit 2021TestJS Summit 2021
38 min
Testing Pyramid Makes Little Sense, What We Can Use Instead
Top Content
Featured Video
Gleb Bahmutov
Roman Sandler
2 authors
The testing pyramid - the canonical shape of tests that defined what types of tests we need to write to make sure the app works - is ... obsolete. In this presentation, Roman Sandler and Gleb Bahmutov argue what the testing shape works better for today's web applications.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
Remix is a web framework that gives you the simple mental model of a Multi-Page App (MPA) but the power and capabilities of a Single-Page App (SPA). One of the big challenges of SPAs is network management resulting in a great deal of indirection and buggy code. This is especially noticeable in application state which Remix completely eliminates, but it's also an issue in individual components that communicate with a single-purpose backend endpoint (like a combobox search for example).
In this talk, Kent will demonstrate how Remix enables you to build complex UI components that are connected to a backend in the simplest and most powerful way you've ever seen. Leaving you time to chill with your family or whatever else you do for fun.
Understanding React’s Fiber Architecture
React Advanced Conference 2022React Advanced Conference 2022
29 min
Understanding React’s Fiber Architecture
Top Content
We've heard a lot about React's Fiber Architecture, but it feels like few of us understand it in depth (or have the time to). In this talk, Tejas will go over his best attempt at understanding Fiber (reviewed by other experts), and present it in an 'explain-like-I'm-five years old' way.
Full-Circle Testing With Cypress
TestJS Summit 2022TestJS Summit 2022
27 min
Full-Circle Testing With Cypress
Top Content
Cypress has taken the world by storm by brining an easy to use tool for end to end testing. It’s capabilities have proven to be be useful for creating stable tests for frontend applications. But end to end testing is just a small part of testing efforts. What about your API? What about your components? Well, in my talk I would like to show you how we can start with end-to-end tests, go deeper with component testing and then move up to testing our API, circ

Workshops on related topic

Designing Effective Tests With React Testing Library
React Summit 2023React Summit 2023
151 min
Designing Effective Tests With React Testing Library
Top Content
Featured Workshop
Josh Justice
Josh Justice
React Testing Library is a great framework for React component tests because there are a lot of questions it answers for you, so you don’t need to worry about those questions. But that doesn’t mean testing is easy. There are still a lot of questions you have to figure out for yourself: How many component tests should you write vs end-to-end tests or lower-level unit tests? How can you test a certain line of code that is tricky to test? And what in the world are you supposed to do about that persistent act() warning?
In this three-hour workshop we’ll introduce React Testing Library along with a mental model for how to think about designing your component tests. This mental model will help you see how to test each bit of logic, whether or not to mock dependencies, and will help improve the design of your components. You’ll walk away with the tools, techniques, and principles you need to implement low-cost, high-value component tests.
Table of contents- The different kinds of React application tests, and where component tests fit in- A mental model for thinking about the inputs and outputs of the components you test- Options for selecting DOM elements to verify and interact with them- The value of mocks and why they shouldn’t be avoided- The challenges with asynchrony in RTL tests and how to handle them
Prerequisites- Familiarity with building applications with React- Basic experience writing automated tests with Jest or another unit testing framework- You do not need any experience with React Testing Library- Machine setup: Node LTS, Yarn
AI on Demand: Serverless AI
DevOps.js Conf 2024DevOps.js Conf 2024
163 min
AI on Demand: Serverless AI
Top Content
Featured WorkshopFree
Nathan Disidore
Nathan Disidore
In this workshop, we discuss the merits of serverless architecture and how it can be applied to the AI space. We'll explore options around building serverless RAG applications for a more lambda-esque approach to AI. Next, we'll get hands on and build a sample CRUD app that allows you to store information and query it using an LLM with Workers AI, Vectorize, D1, and Cloudflare Workers.
How to Start With Cypress
TestJS Summit 2022TestJS Summit 2022
146 min
How to Start With Cypress
Featured WorkshopFree
Filip Hric
Filip Hric
The web has evolved. Finally, testing has also. Cypress is a modern testing tool that answers the testing needs of modern web applications. It has been gaining a lot of traction in the last couple of years, gaining worldwide popularity. If you have been waiting to learn Cypress, wait no more! Filip Hric will guide you through the first steps on how to start using Cypress and set up a project on your own. The good news is, learning Cypress is incredibly easy. You'll write your first test in no time, and then you'll discover how to write a full end-to-end test for a modern web application. You'll learn the core concepts like retry-ability. Discover how to work and interact with your application and learn how to combine API and UI tests. Throughout this whole workshop, we will write code and do practical exercises. You will leave with a hands-on experience that you can translate to your own project.
Detox 101: How to write stable end-to-end tests for your React Native application
React Summit 2022React Summit 2022
117 min
Detox 101: How to write stable end-to-end tests for your React Native application
Top Content
WorkshopFree
Yevheniia Hlovatska
Yevheniia Hlovatska
Compared to unit testing, end-to-end testing aims to interact with your application just like a real user. And as we all know it can be pretty challenging. Especially when we talk about Mobile applications.
Tests rely on many conditions and are considered to be slow and flaky. On the other hand - end-to-end tests can give the greatest confidence that your app is working. And if done right - can become an amazing tool for boosting developer velocity.
Detox is a gray-box end-to-end testing framework for mobile apps. Developed by Wix to solve the problem of slowness and flakiness and used by React Native itself as its E2E testing tool.
Join me on this workshop to learn how to make your mobile end-to-end tests with Detox rock.
Prerequisites- iOS/Android: MacOS Catalina or newer- Android only: Linux- Install before the workshop
API Testing with Postman Workshop
TestJS Summit 2023TestJS Summit 2023
48 min
API Testing with Postman Workshop
Top Content
WorkshopFree
Pooja Mistry
Pooja Mistry
In the ever-evolving landscape of software development, ensuring the reliability and functionality of APIs has become paramount. "API Testing with Postman" is a comprehensive workshop designed to equip participants with the knowledge and skills needed to excel in API testing using Postman, a powerful tool widely adopted by professionals in the field. This workshop delves into the fundamentals of API testing, progresses to advanced testing techniques, and explores automation, performance testing, and multi-protocol support, providing attendees with a holistic understanding of API testing with Postman.
1. Welcome to Postman- Explaining the Postman User Interface (UI)2. Workspace and Collections Collaboration- Understanding Workspaces and their role in collaboration- Exploring the concept of Collections for organizing and executing API requests3. Introduction to API Testing- Covering the basics of API testing and its significance4. Variable Management- Managing environment, global, and collection variables- Utilizing scripting snippets for dynamic data5. Building Testing Workflows- Creating effective testing workflows for comprehensive testing- Utilizing the Collection Runner for test execution- Introduction to Postbot for automated testing6. Advanced Testing- Contract Testing for ensuring API contracts- Using Mock Servers for effective testing- Maximizing productivity with Collection/Workspace templates- Integration Testing and Regression Testing strategies7. Automation with Postman- Leveraging the Postman CLI for automation- Scheduled Runs for regular testing- Integrating Postman into CI/CD pipelines8. Performance Testing- Demonstrating performance testing capabilities (showing the desktop client)- Synchronizing tests with VS Code for streamlined development9. Exploring Advanced Features - Working with Multiple Protocols: GraphQL, gRPC, and more
Join us for this workshop to unlock the full potential of Postman for API testing, streamline your testing processes, and enhance the quality and reliability of your software. Whether you're a beginner or an experienced tester, this workshop will equip you with the skills needed to excel in API testing with Postman.
Testing Web Applications Using Cypress
TestJS Summit - January, 2021TestJS Summit - January, 2021
173 min
Testing Web Applications Using Cypress
WorkshopFree
Gleb Bahmutov
Gleb Bahmutov
This workshop will teach you the basics of writing useful end-to-end tests using Cypress Test Runner.
We will cover writing tests, covering every application feature, structuring tests, intercepting network requests, and setting up the backend data.
Anyone who knows JavaScript programming language and has NPM installed would be able to follow along.