4

Deciding on the Best Cloud-Based Solution

When designing your application to make it cloud-based, you must understand different architectural designs – from the simplest to the most sophisticated. This chapter discusses different software architecture models and teaches you how to take advantage of the opportunities offered by the cloud in your solutions. This chapter will also discuss the different types of cloud service that we can consider while developing our infrastructure, what the ideal scenarios are, and where we can use each of them.

The following topics will be covered in this chapter:

  • Infrastructure as a Service solutions
  • Platform as a Service solutions
  • Software as a Service solutions
  • Serverless solutions
  • How to use hybrid solutions and why they are so useful

It is worth mentioning that the choice to be made between these options depends on different aspects of the project scenario. This will also be discussed in the chapter.

Technical requirements

For the practical content in this chapter, you must create or use an Azure account. We explained the account creation process in Chapter 1, Understanding the Importance of Software Architecture, in the Creating an Azure account section.

Different software deployment models

Cloud solutions can be deployed with different models. The way you decide to deploy your applications depends on the kind of team you work with. In companies where you have infrastructure engineers, you will probably find more people working with Infrastructure as a Service (IaaS).

On the other hand, in companies where IT is not the core business, you will find a bunch of Software as a Service (SaaS) systems. It is common for developers to decide to use the Platform as a Service (PaaS) option, or to go serverless, as they have no need to deliver infrastructures in this scenario.

As a software architect, you must cope with this environment and be sure that you are optimizing the cost and work factors, not only during the initial development of the solution but also during its maintenance. Also, as an architect, you must understand the needs of your system and work hard to connect those needs to best-in-class peripheral solutions to speed up delivery and keep the solution as close as possible to the customer’s specifications.

IaaS and Azure opportunities

Infrastructure as a Service was the first generation of cloud services provided by many different cloud players. Its definition is easily found in many places, but we can summarize it as “your computing infrastructure delivered on the internet, hosted somewhere that you do not manage.” In the same way that we have virtualization of services in a local data center, IaaS will also give you virtualized components, such as servers, storage, and firewalls, in the cloud.

In Azure, several services are provided with an IaaS model. Most of them are paid for and you should pay attention to this when it comes to testing. It is worth mentioning that this book does not set out to describe all IaaS services that Azure provides in detail. However, as a software architect, you just need to understand that you will find services such as the following:

  • Virtual machines: Windows Server, Linux, Oracle, data science, and machine learning
  • Network: Virtual networks, load balancers, and DNS zones
  • Storage: Files, tables, databases, and Redis

Obviously, these are not the only ones available as IaaS models, so the first step is to look at the service options that we have in Azure. To create any service in Azure, you must find the service that best fits your needs and then create a resource. The following screenshot shows a Windows Server virtual machine being configured.

Interface gráfica do usuário, Texto, Aplicativo  Descrição gerada automaticamente

Figure 4.1: Creating a virtual machine in Azure

Following the wizard provided by Azure to set up your virtual machine, you will be able to connect to it by using Remote Desktop Protocol (RDP). The next screenshot presents some of the hardware options you have for deploying a virtual machine. It is curious to think about it, considering the different capacities we have available just by clicking on the Select button.

Interface gráfica do usuário, Aplicativo  Descrição gerada automaticamente

Figure 4.2: Virtual machine sizes available in Azure

If you compare the on-premises velocity to deliver hardware with the cloud velocity, you will realize that there is nothing better than the cloud when it comes to time-to-market. For instance, there are machines with 64 CPUs, 256 GB of RAM, and temporary storage of 512 GB. This is something you probably will not find in an on-premises data center, for instance, if you have a temporary workload or it will take you a lot to deliver if you have a brand-new business idea that needs this computing power. Besides, in the temporary workload scenario, this machine will be underutilized, so it would be impossible to justify its purchase in an on-premises scenario. That is the reason why cloud computing is so amazing!

Security responsibility in IaaS

Security responsibility is another important thing to know about an IaaS platform. Many people think that once you decide to go on the cloud, all the security is done by the provider. However, this is not true, as you can see in the following screenshot:

D:NehaOFFICECMEPENEpub to Word styB16756_EPUBB16756_EPUBOEBPSImagesB16756_04_03.png

Figure 4.3: Managing security in cloud computing

IaaS will force you to take care of security from the operating system to the application. In some cases, this is inevitable, but you must understand that this will increase your system cost.

IaaS can be a good option if you just want to move an already existing on-premises structure to the cloud. This enables scalability, due to the tools that Azure gives you along with all the other services. However, if you are planning to develop an application from scratch, you should also consider other options available on Azure.

Let’s look at one of the fastest systems in the next section, that is, PaaS.

PaaS – a world of opportunities for developers

If you are studying or have studied software architectures, you will probably perfectly understand the meaning of the next sentence: The world demands high speed when it comes to software development! If you agree with this, you will love PaaS.

As you can see in the preceding screenshot, PaaS allows you to worry about security only in terms of aspects that are closer to your business: your data and applications. For developers, this represents freedom from having to implement a bunch of configurations that make your solution work safely.

Security handling is not the only advantage of PaaS. As a software architect, you can introduce these services as an opportunity to deliver richer solutions faster. Time-to-market can surely justify the cost of many applications that run on a PaaS basis.

There are lots of services delivered as PaaS nowadays in Azure and, again, it is not the purpose of this book to list all of them. However, some do need to be mentioned. The list keeps growing and the recommendation here is: use and test these services as much as you can! Make sure that you will deliver better-designed solutions with this thought in mind.

On the other hand, it is worth mentioning that, with PaaS solutions, you will not have full control of the operating system. In fact, in many situations, you do not even have a way to connect to it. This is good most of the time, but in some debugging situations, you may miss this feature. The good thing is that PaaS components are evolving every single day and one of the biggest concerns from Microsoft is making them widely visible.

The following sections present the most common PaaS components delivered by Microsoft for .NET web apps, such as Azure Web Apps and Azure SQL Server. We also describe Azure Cognitive Services, a very powerful PaaS platform that demonstrates how wonderful development is in the PaaS world. We will explore some of them in greater depth in the remainder of this book.

Web apps

A web app is a PaaS option you can use to deploy your web app. You can deploy different types of application, such as .NET, .NET Core, Java, PHP, Node.js, and Python. An example of this was presented in Chapter 1, Understanding the Importance of Software Architecture.

The good thing is that creating a web app does not require any structure and/or IIS web server setup. In some cases, where you are using Linux to host your .NET application, you do not have IIS at all.

Moreover, web apps have a plan option where you do not need to pay for usage. Of course, there are limitations, such as only running 32-bit apps and failing to enable scalability, but this can be a wonderful scenario for prototyping.

SQL databases

Imagine how quickly you can deploy a solution if you have the complete power of a SQL server without needing to pay for a big server to deploy this database. This applies to SQL databases. With them, you can use Microsoft SQL Server for what you need the most – storage and data processing. In this scenario, Azure assumes responsibility for backing up the database.

The SQL database even gives you the option to manage performance by itself. This is called automatic tuning. Again, with PaaS components, you will be able to focus on what is important to your business: a very fast time-to-market.

The steps for creating a SQL database for testing are quite simple, like what we have seen with other components. However, there are two things you need to pay attention to: the creation of the server and how you will be charged. Besides, in a production scenario, there are quite a lot more steps to consider.

When you create a resource, you can search for SQL Database and you will find this wizard to help you:

D:NehaOFFICECMEPENEpub to Word styB16756_EPUBB16756_EPUBOEBPSImagesB16756_04_04.png

Figure 4.4: Creating a SQL database in Azure

The SQL database depends on a SQL server to host it. For this reason, as you can see, you must create (at least for the first database) a database.windows.net server, where your databases will be hosted. This server will provide all the parameters you need to access the SQL server database using current tools, such as Visual Studio, SQL Server Management Studio, and Azure Data Studio. It is worth mentioning that you have a bunch of features regarding security, such as Transparent Data Encryption and IP firewalls.

As soon as you decide on the name of your database server, you will be able to choose the pricing tier on which your system will be charged. Especially in SQL databases, there are several different pricing options, as you can see in the following screenshot. You should study each of them carefully because, depending on your scenario, you may save money by optimizing a pricing tier:

D:NehaOFFICECMEPENEpub to Word styB16756_EPUBB16756_EPUBOEBPSImagesB16756_04_05.png

Figure 4.5: Configuring the Azure SQL Database pricing tier

For more information about SQL configuration, you can use this link: https://azure.microsoft.com/en-us/services/sql-database/.

Once you have completed the configuration, you will be able to connect to this server database in the same way you do when your SQL server is installed on-premises. The only detail that you must pay attention to is the configuration of the Azure SQL Server firewall, but this is quite simple to set up and a good demonstration of how safe the PaaS service is.

Azure Cognitive Services

Artificial Intelligence (AI) is one of the most frequently discussed topics in software architecture. We are a step away from a really great world where AI will be everywhere. To make this come true, as a software architect you cannot think about AI as software you need to invent from scratch all the time.

Azure Cognitive Services can help you with this. In this set of APIs, you will find various ways to develop vision, knowledge, speech, search, and language solutions. Some of them need to be trained to make things happen, but these services provide APIs for that too.

The great thing about PaaS is evident from this scenario. The number of jobs you will have to perform to prepare your application in an on-premises or IaaS environment is enormous. In PaaS, you just do not need to worry about this. You are totally focused on what really matters to you as a software architect: the solution to your business problem.

Setting up Azure Cognitive Services in your Azure account is also quite simple. First, you will need to add Cognitive Services like any other Azure component, as you can see in the following screenshot:

D:NehaOFFICECMEPENEpub to Word styB16756_EPUBB16756_EPUBOEBPSImagesB16756_04_06.png

Figure 4.6: Creating a Cognitive Services API in Azure

As soon as you have done this, you will be able to use the APIs provided by the server. You will find two important features in the service that you have created: endpoints and access keys. They are going to be used in your code to access APIs.

D:NehaOFFICECMEPENEpub to Word styB16756_EPUBB16756_EPUBOEBPSImagesB16756_04_07.png

Figure 4.7: Cognitive Services endpoint created

The following code sample shows how you can use the Cognitive Services API to translate sentences. The main concept underlying this translation service is that you can post the sentence you want to translate, according to the key and region where the service was set. The following code enables you to post a request to the service API:

private static async Task<string> PostAPI(string api, string key, string region, string textToTranslate)
{
    using var client = new HttpClient();
    client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key);
    client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Region", region);
    client.Timeout = TimeSpan.FromSeconds(5);
    var body = new[] { new { Text = textToTranslate } };
    var requestBody = JsonConvert.SerializeObject(body);
    var content = new StringContent(requestBody, Encoding.UTF8, "application/json");
    var response = await client.PostAsync(api, content);
    response.EnsureSuccessStatusCode();
    return await response.Content.ReadAsStringAsync();
}

It is worth mentioning that the preceding code will allow you to post requests to translate any text into any language, provided you define it in the parameters. The following is the main program that calls the previous method:

static async Task Main()
{
    var host = "https://api.cognitive.microsofttranslator.com";
    var route = "/translate?api-version=3.0&to=es";
    var subscriptionKey = "[YOUR KEY HERE]";
    var region = "[YOUR REGION HERE]";
    if (subscriptionKey == "[YOUR KEY HERE]")
    {
        Console.WriteLine("Please, enter your key: ");
        subscriptionKey = Console.ReadLine();
    }
    if (region  == "[YOUR REGION HERE]")
    {
        Console.WriteLine("Please, enter your region: ");
        region = Console.ReadLine();
    }
    var translatedSentence = await PostAPI(host + route, subscriptionKey, region, "Hello World!");
    Console.WriteLine(translatedSentence);
    Console.WriteLine("Press any key to continue...");
    Console.ReadKey();
}

This is a perfect example of how easily and quickly you can use services such as this to architect your projects. Also, this kind of approach to development is wonderful, since you are using a piece of code that’s already been tested and used by other solutions.

SaaS – just sign in and get started!

SaaS is probably the easiest way to use cloud-based services. Cloud players provide many good options that solve common problems in a company for their end users.

A good example of this type of service is Office 365. The key point with these platforms is that you do not need to worry about application maintenance. This is particularly convenient in scenarios where your team is totally focused on developing the core business of the application. For example, if your solution needs to deliver good reports, maybe you can design them using Power BI (which is included in Office 365).

Another pretty good example of a SaaS platform is Azure DevOps. As a software architect, before Azure DevOps, you needed to install and configure Team Foundation Server (TFS) (or even older tools like Microsoft Visual SourceSafe) to have your team working with a common repository and an application life cycle management tool.

We used to spend a lot of time just working either on preparing the server for TFS installation or on upgrading and continuously maintaining the TFS already installed. This is no longer needed due to the simplicity of SaaS Azure DevOps.

Understanding what serverless means

A serverless solution is a solution where the focus is not on where the code runs. Even in a “serverless” solution, there is always a server. The thing is that you just do not know or care which server your code executes on.

You may now be thinking that serverless is just another option – of course, this is true, as this architecture does not deliver a complete solution. But the key point here is that, in a serverless solution, you have a very fast, simple, and agile application life cycle since almost all serverless code is stateless and loosely coupled with the remainder of the system. Some authors refer to this as Function as a Service (FaaS).

Of course, the server runs somewhere. The key point here is that you do not need to worry about this or even scalability. This will enable you to focus completely on your app’s business logic. Again, the world needs fast development and good customer experiences at the same time. The more you focus on customer needs, the better!

In Chapter 9, Working with Azure Functions, you will explore one of the best serverless implementations that Microsoft provides in Azure – Azure Functions. There, we will focus on how you can develop serverless solutions and learn about their advantages and disadvantages.

Why are hybrid applications so useful in many cases?

Hybrid solutions are solutions whose parts do not share a uniform architectural choice; each part makes a different architectural choice. In the cloud, the word hybrid refers mainly to solutions that mix cloud subsystems with on-premises subsystems. However, it can refer also to mixing web subsystems with device-specific subsystems, such as mobiles or any other device that runs code.

Due to the number of services Azure can provide and the number of design architectures that can be implemented, hybrid applications are probably the best answer to the main question addressed in this chapter, that is, how to use the opportunities offered by the cloud in your projects.

Nowadays, many current projects are moving from an on-premises solution to a cloud architecture and, depending on where you are going to deliver these projects, you will still find many bad preconceptions regarding moving to the cloud. Most of them are related to cost, security, and service availability.

You need to understand that there is some truth in these preconceptions, but not in the way people think. For sure, you as a software architect cannot ignore them. Especially when you develop a critical system, you must decide whether everything can go on the cloud or whether it is better to deliver part of the system on the edge.

The edge computing paradigm is an approach used to have part of the system deployed on machines or devices closer to the location they are needed. This helps with reducing response times and the amount of bandwidth used.

Mobile solutions can be considered a classic example of hybrid applications, since they mix a web-based architecture with a device-based architecture to offer a better user experience. There are lots of scenarios where you can replace a mobile application with a responsive website. However, when it comes to interface quality and performance, maybe a responsive website will not give the end user what they really need.

In the next section, we will discuss a practical example.

Book use case – which is the best cloud solution?

If you go back to Chapter 1, Understanding the Importance of Software Architecture, you will find a system requirement that describes the system environments where our WWTravelClub example application is supposed to run.

SR_003: The system shall run on Windows, Linux, iOS, and Android platforms.

At first sight, any developer would respond by saying web apps. However, the iOS and Android platforms will also need your attention as a software architect. In this scenario, as in several scenarios, user experience is the key to the success of the project. The decision needs to be driven not only by development speed but again by the benefits gained by delivering a great user experience.

Another decision that the software architect must make in this project is related to the technology for the mobile application, if they decide to develop one. Again, this is going to be a choice between hybrid and native apps since, in this case, a cross-platform solution such as Xamarin can be used. So, with mobile applications, you also have the option to keep writing the code in C#.

The following screenshot represents our first choice for the WWTravelClub architecture. The decision to rely on Azure components is related to cost and maintenance considerations. Each of the following items will be discussed later in this book, in Chapter 7, Interacting with Data in C# – Entity Framework Core, Chapter 8, How to Choose Your Data Storage in the Cloud, and Chapter 9, Working with Azure Functions, together with the reasons for the choice. For now, it is enough to know that WWTravelClub is a hybrid application, running Xamarin Apps on mobiles and an ASP.NET Core web app on the server side.

D:NehaOFFICECMEPENEpub to Word styB16756_EPUBB16756_EPUBOEBPSImagesB16756_04_08.png

Figure 4.8: WWTravelClub architecture

As you can verify in the picture, the WWTravelClub architecture was designed mainly with PaaS and serverless components provided by Azure. All the development will be conducted on the Azure DevOps SaaS Microsoft platform.

In the imaginary scenario we have with WWTravelClub, the sponsors have indicated that no one in the WWTravelClub team specializes in infrastructure. Therefore, the software architecture uses PaaS services. Considering this scenario and the required development speed, these components will surely perform well.

While we fly through the chapters and technologies discussed in this book, this architecture will change and evolve without being constrained by any earlier choices. This is a great opportunity offered by Azure and by modern architecture design. You can easily change components and structures as your solution evolves.

Summary

In this chapter, you learned how to take advantage of the services offered by the cloud in your solutions, and the various options you can choose from.

This chapter covered different ways to deliver the same application in a cloud-based structure. We also noted how rapidly Microsoft is delivering all these options to its customers, because you can experience all of these options in actual applications and choose the one that best fits your needs since there is no silver bullet that works in all situations. As a software architect, you need to analyze your environment and your team, and then decide on the best cloud architecture to implement in your solution.

The next chapter is dedicated to how to build a flexible architecture made up of small scalable software modules called microservices.

Questions

  1. Why should you use IaaS in your solution?
  2. Why should you use PaaS in your solution?
  3. Why should you use SaaS in your solution?
  4. Why should you use serverless in your solution?
  5. What is the advantage of using an Azure SQL Server database?
  6. How can you accelerate AI in your application with Azure?
  7. How can hybrid architectures help you to design a better solution?

Further reading

You can check out these web links to study the topics covered in this chapter in greater depth:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.190.232