title
stringlengths
3
46
content
stringlengths
0
1.6k
10:18
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, speeding up delivery and keeping the solution as close as possible to the customer’s specifications.
10:19
IaaS and Azure opportunities
10:20
IaaS 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.
10:21
In a few words, all the hardware you need is hosted in the cloud and maintained by the cloud provider instead of being hosted in your private data center. This includes servers delivered as virtual machines, possibly connected to private networks, disk storage, and also firewalls. You don’t buy the hardware but pay for its usage, and you can scale to a more powerful configuration at zero cost.
10:22
You can access your cloud hardware as if it were hosted in your private data center, but hardware maintenance is taken care of by the cloud provider. Moreover, you can scale your hardware gradually as your application traffic increases without installation and purchase costs and without migrating data to new hardware. Scaling is performed with simple configuration instructions.
10:23
Among the various cloud providers, Azure is the one with the most complete and varied offer, so you can easily find a perfect match with any hardware need. Most Azure IaaS solutions 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 do need to understand that you will find services such as the following:
10:24
10:25
Virtual machines: Windows Server, Linux, Oracle, data science, and machine learning
10:26
Network: Virtual networks, load balancers, and DNS zones
10:27
Storage: Files, tables, databases, and Redis
10:28
10:29
Obviously, these are not the only ones available as IaaS models, so the first step is to look at the service options available 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.
10:30
10:31
Figure 10.1: Creating a virtual machine in Azure
10:32
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 interesting to consider the vast array of hardware options at our disposal for deploying a virtual machine, especially when considering that these can be accessed just by clicking on the Select button.
10:33
10:34
Figure 10.2: Virtual machine sizes available in Azure
10:35
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.
10:36
IaaS can be adopted when you want full control over your infrastructure while still benefiting from cloud computing advantages like redundancy and scalability. However, the time-to-market for IaaS solutions is similar to that for on-premises solutions. Therefore, it is convenient to start with options that allow for a quicker launch in the short run and consider transitioning to IaaS for long-term objectives.
10:37
Security responsibility in IaaS
10:38
Security is an essential aspect of all hardware solutions because hacker attacks might cause both service interruptions and leaks or loss of important business data.
10:39
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:
10:40
10:41
Figure 10.3: Managing security in cloud computing
10:42
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.
10:43
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.
10:44
Shifting our focus to PaaS, we enter a realm where speed and efficiency in software development take center stage. PaaS provides an environment where businesses can develop, run, and manage applications without the complexity of building and maintaining the infrastructure.
10:45
PaaS – a world of opportunities for developers
10:46
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! This demand for speed is precisely where PaaS becomes invaluable, offering rapid development and deployment capabilities.
10:47
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.
10:48
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.
10:49
PaaS solutions free you from managing all details involved in your solution deployment without creating an excessive dependency on the PaaS supplier. In fact, your software need not depend too much on the chosen PaaS and small dependencies can be isolated in adequately designed drivers. In other words, it is always easy to move to a different PaaS solution or an IaaS solution if the software is designed with driver-based architecture, like the Onions architecture we described in the Layers and the Onion architecture section of Chapter 7, Understanding the Different Domains in Software Solutions. Therefore, PaaS may be a good choice to reduce time-to-market also when one plans to move to IaaS in the long run.
10:50
Delving deeper into PaaS, let’s examine how Azure implements this model through its diverse range of services. Azure’s PaaS offerings are designed to cater to various development needs, from web applications to complex data processing.
10:51
There are lots of services delivered as PaaS nowadays in Azure, and the array of available services is continuously expanding, reflecting the evolving needs of developers and businesses.
10:52
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 to use and test these services as much as you can! Make sure that you will deliver better-designed solutions with this thought in mind.
10:53
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 to have a way to connect to it. This is fine 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 Microsoft’s biggest concerns is making them widely visible.
10:54
The following subsections introduce the most common PaaS components delivered by Microsoft for .NET web apps, that is, 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.
10:55
Of the many PaaS services, web apps stand out for their versatility and ease of use. Azure’s web app service simplifies the deployment of various types of applications, demonstrating the practicality and accessibility of PaaS solutions.
10:56
Web apps
10:57
A web app is a PaaS option you can use to deploy your web app. You can deploy different types of applications, 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.
10:58
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. Web apps’ flexibility in hosting options, such as not requiring IIS for Linux-based deployments, underscores their adaptability to various development and deployment environments.
10:59
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. This free tier is ideal for learning and initial application prototyping, offering essential features without the financial commitment.
10:60
SQL databases
10:61
Imagine how quickly you can deploy a solution if you have the complete power of an 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.
10:62
Here, we will discuss briefly the advantages of having your databases in the cloud. Databases are discussed in detail in both Chapter 12, Choosing Your Data Storage in the Cloud, and Chapter 13, Interacting with Data in C# – Entity Framework Core.
10:63
Say you are starting a new business application, and say, initially, your data storage and traffic requirements are quite low, but you need advanced features such as data replication to safeguard your data and offer high performance to geographically distributed users. Without Azure SQL databases, you would be forced to buy several SQL licenses since the SQL Server free edition doesn’t cover similar scenarios.
10:64
With Azure SQL databases, instead, you can have the top features of the SQL Server Enterprise edition without paying for an expensive license, paying instead just for your initially small storage and traffic needs.
10:65
The SQL database even gives you the option to manage performance by itself. This is called automatic tuning – that is, your traffic requirements are automatically scaled to keep response time acceptable as requests increase. This means that your costs might automatically increase, but you can also define maximum expense limits.
10:66
Again, with PaaS components, you will be able to focus on what is important to your business: a very fast time-to-market.
10:67
The steps to create 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. In fact, understanding the various configurations and their costs is essential to finding the best trade-off between your application and maximum cost requirements.
10:68
When you create a resource, you can search for SQL Database, and you will find this wizard to help you:
10:69
10:70
Figure 10.4: Creating a SQL database in Azure
10:71
The SQL database depends on an 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 security features, such as Transparent Data Encryption and IP firewalls.
10:72
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 can save money by optimizing a pricing tier:
10:73
10:74
Figure 10.5: Configuring the Azure SQL Database Pricing Tier
10:75
For more information about SQL configuration, you can use this link: https://azure.microsoft.com/en-us/services/sql-database/.
10:76
More details on database solutions are discussed in Chapter 12, Choosing Your Data Storage in the Cloud, and Chapter 13, Interacting with Data in C# - Entity Framework Core.
10:77
Once you have completed the configuration, you will be able to connect to this server database in the same way you did when your SQL server was 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.
10:78
Azure Cognitive Services
10:79
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.
10:80
For instance, AI is gaining ever more importance in the field of automatic help centers, data analysis to drive business decisions, and user interfaces based on natural language. The economic value added to these areas by AI is enormous, both in the decrease of service costs and in the increase in profit due to optimized decision-making.
10:81
To realize this, as a software architect, you cannot think about AI as software you need to invent from scratch all the time.
10:82
Azure Cognitive Services can help you with this. These APIs empower developers to create advanced features, like voice recognition in apps or language translation in customer service tools, with relative ease.
10:83
The great thing about PaaS is evident from this scenario. The cost of developing an in-house AI solution would require both enormous investments and hard-to-find competencies. With Azure Cognitive Services’ PaaS, instead, you just don’t need to worry about AI techniques. Instead, you may remain focused on what really matters to you as a software architect: the solution to your business problem.
10:84
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. You can choose a specific cognitive service or a multi-service account that will enable you to access all cognitive services. In the screenshot below, we have chosen a multi-service account:
10:85
10:86
Figure 10.6: Creating a Cognitive Services API account in Azure
10:87
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.
10:88
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:
10:89
private static async Task<string> CSTranslate(string api, string key, string region, string textToTranslate)
10:90
{
10:91
using var client = new HttpClient();
10:92
client.DefaultRequestHeaders.Add(`Ocp-Apim-Subscription-Key`, key);
10:93
client.DefaultRequestHeaders.Add(`Ocp-Apim-Subscription-Region`, region);
10:94
client.Timeout = TimeSpan.FromSeconds(5);
10:95
var body = new[] { new { Text = textToTranslate } };
10:96
var requestBody = JsonConvert.SerializeObject(body);
10:97
var content = new StringContent(requestBody, Encoding.UTF8, `application/json`);
10:98
var response = await client.PostAsync(api, content);
10:99
response.EnsureSuccessStatusCode();
10:100
return await response.Content.ReadAsStringAsync();
10:101
}
10:102
10:103
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:
10:104
static async Task Main()
10:105
{
10:106
var host = `https://api.cognitive.microsofttranslator.com`;
10:107
var route = `/translate?api-version=3.0&to=es`;
10:108
var subscriptionKey = `[YOUR KEY HERE]`;
10:109
var region = `[YOUR REGION HERE]`;
10:110
if (subscriptionKey == `[YOUR KEY HERE]`)
10:111
{
10:112
Console.WriteLine(`Please, enter your key: `);
10:113
subscriptionKey = Console.ReadLine();
10:114
}
10:115
if (region == `[YOUR REGION HERE]`)
10:116
{
10:117
Console.WriteLine(`Please, enter your region: `);