×
Community Blog Building Enterprise-Grade Caching Service on Alibaba Cloud

Building Enterprise-Grade Caching Service on Alibaba Cloud

In this article, we will discuss about server-side caching technologies, especially Redis, and show you how we can deploy a Redis caching server on Alibaba Cloud.

By Afzaal Ahmad Zeeshan, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Background

For decades, we have been in a cycle where we synthesize information in a new dimension with the wisdom of the past, and by reusing the same contexts and concepts, we keep reinventing. This is a continually evolving process that keeps the software industry revolving. In the same way, we have the dynamics of databases. Databases are not just used to store the data after a transaction has been processed, with the advent of real-time systems, and single-page ecommerce applications, our customers require our applications to remember what they were doing. Either being on the client-side or on the server-side. Formally, we used to work with in-memory databases, which stores the entire dataset in RAM (Random-Access-Memory), unlike the traditional and on-disk database system. Working with the in-memory database was not less than a charm because or several benefits that we get,

  • It is blazingly fast to access the data kept in the main memory
  • It is also simpler in design and it requires lower memory and CPU usage.

However, this ease diminishes when the system gets rebooted or your program crashes because you will not be able to recover this data ever again. Later, it became possible to empower the in-memory database with caching (in-memory-database to in-memory-cashing), to resolve the data persistence and durability issues.

With time, it has been realized that due to high request rate (input-output- requests-per-seconds), the additional resources such as more RAM and CPU, which ultimately mean your cost, as well as the management, is increasing. This management and the cost-shift will look satisfied in the peak business hours and craziest occasional traffic loads. And combining all this with the session state management, customer information on a transaction, sometimes it is obvious that we require a solution that does not cost us much, each year. In several of my own projects, I have utilized caching solutions that help me maintain a good performance for my app. Although caching and storage is available on client as well as server-side, we will mostly talk about the server-side caching technologies, especially Redis and how we can deploy a Redis caching server on Alibaba Cloud.

Why Cloud?

Redis works in-memory and provides a high throughput for your applications. Working in-memory requires a good suitable and large container for your memory requirements. In a general environment, your RAM is the component that wears out quickly. Over the course of decades, price of RAM has dropped fairly for your own on-premises datacenter development, but even with this scenario you cannot expect everything to work out as planned. Cloud providers and solutions work quite well in many scenarios, and the thing is, you do not have to worry about the infrastructure and setup costs—most cloud providers always provide the latest hardware technology for your solutions, so you also do not need to worry about upgrading your hardware.

Among variety of obvious reasons to think about a cloud provider for your data caching, the most prominent ones would be; accessibility, instant backup, and recovery. Because the data caching isn't a new concept, it has been around since ages now, and everyone – from a small business holder to a giant vendor (such as email services, image, and video sharing sites and other large enterprises) need a durable and expeditious cloud storage that can store and manage their data.

In the coming sections, we will explore the benefit that Alibaba Cloud users have when it comes to Redis deployment and management on the cloud scale. I would want to explore and show you how easy it is, to manage the cluster size, and provision the usage of the servers.

How ApsaraDB implements Redis Cache

Before speaking about Alibaba Cloud ApsaraDB for Redis and having an insightful concept about its implementation and controls, let's talk about Redis itself. Because Alibaba has developed ApsaraDB for Redis entirely based on the actual Redis Protocol, it supports version 2.8 and 4 of Redis protocol, and we will see how they both differ in providing the services, to customers, but in a later section.

Redis (remote data structure server) is an in-memory database, with a range of data types, it stores and sorts data automatically. Your application's processes can access Redis from multiple different nodes; moreover, to make high availability of data possible, it replicates its activities with leader-follower (master-slave) mechanism. In short, if your application requires scalability and sharing of the same data on different nodes, then Redis is for you, it have built-in support for replication and distribution of data among cluster.

Due to high performance and ease of use, it is no surprise that all the mega cloud storage providers have implemented Redis to drive up its features. Similarly, ApsaraDB for Redis provides high persistency with a wide range of flexible architecture models – standard architecture and Cluster architecture, this is because Alibaba Cloud serves a wide range of business level requirements such as excessive read/write requests, capacity adjustments, and security strings. To be precise, ApsaraDB spins in-memory caching performance in the following ways:

  1. ApsaraDB for Redis is highly compatible with all the datatypes defined in the open-sourced Redis protocol; this compatibility serves the existing tools and clients such as Jedis, which means all Redis clients can easily be configured with ApsaraDB for a range of supported data operations.
  2. Its management console provides one-click solutions to updating and modifying the configurations for your servers, during the creation and after that as well.
  3. It comes with a master-slave dual node for every instance; it avoids service interruptions which are caused by a single point of failure. Moreover, it detects any sort of hardware failure and switches or replicates the node within a few seconds. ApsaraDB itself maintains a cluster of at least 3 nodes for your clusters so that fail-over is possible without a downtime.
  4. Another top of the stake feature is its support for two different architectural deployment models; master-slave, or replicated, which we have discussed in the above point, in which data is synchronized between the master and slave nodes, it guarantees the high service availability. The other model is, clustered architecture which follows the distributed model, it eases us with disaster recovery and fault migration, also enables us to shard the data across multiple machines.

Now, let us dive in a head and discuss how to create instances of ApsaraDB for Redis on the online portal for Alibaba Cloud.

Purchasing ApsaraDB for Redis

ApsaraDB offers pay-as-you-go and subscription-based model, in both models the product behavior is same; you get the Redis server that can be used for

  • Key-value store
  • Publish-subscribe

However, the most important difference is that once you create a type you cannot change it on the runtime—that is a limitation of Redis protocol itself. ApsaraDB for Redis can be purchased as an upfront payment, where you get various benefits and more support, or you can also try it out as a Pay-as-you-Go model.

1
Figure 1: Purchase panel for ApsaraDB for Redis

There are several data centers where you can deploy your solutions. This is the most primary thing to realize and understand in this overall process of deployment. A solution in the cloud can only help you, if you have deployed it closer to your audience. A solution deployed in a different region will not be able to help you out—latency would be higher. Next you get to select the version of the Redis protocol, the type of the nodes and the architecture of your application depends on the type of payment model you have, as well as the version you select. In Pay-as-you-Go mode, version 4 does not support clustered mode. You can use clustered mode with version 2.8, but you miss out the features and improvements provided in version 4. See the image below,

2
Figure 2: Pay-as-you-Go purchase model for ApsaraDB for Redis

Rest of the configurations are simply the ways to setup your system. You specify the size of the cluster you want, you can setup where you want to deploy, which network you want to deploy in, and so on. Once you are happy with the configurations that you have selected here, you can go ahead and create the instance. Alibaba Cloud will send you a notification, once your instance has been created and you can then use that instance to perform other actions, like accessing the resources, or making more changes to it. As you can see, my instance has been created and is ready to be used,

3
Figure 3: ApsaraDB for Redis instance list and status of our instance

Most of the information is already shown on this page, and you can use it—the instance information, payment options, network used etc. You can then go ahead in each of your instances and configure them from there, let's see how to do that in the next section.

Configuring ApsaraDB for Redis Instance

Most basic of the configurations can be performed on the overview—default—page of the ApsaraDB for Redis Instance.

4
Figure 4: Basic configuration for our ApsaraDB for Redis instance

Everything from the basic network information, all the way to core Redis information like max number of clients is shown over here. Portal also shares the other tabs where you can configure more details about your subscription and service. Let's take a quick look at all of those.

Architecture

As I have already mentioned, ApsaraDB itself maintains the architecture in a way that lets you not worry about the underlying high-availability for your resources. The architecture for the subscription that I have bought is something like this,

5
Figure 5: Architecture of our purchased service.

As you can see, the front-end of the service is then managed at the backend by internal services, proxies—you can think of them as load balancers. Your requests go through them and then they reach the layers where your data is maintained. Your data is also persisted so that your applications can rely on the data being there. A master-slave relationship is created for our solution, to maintain the backups as well.

Connectivity

ApsaraDB for Redis is deployed on the internal networks—VPCs where your services are configured for the internal DNS to be resolved for. This service is not available on the public internet, so you must access the resources from within the network and expose them via a web app, or a VM that might listen to these changes and perform actions.

However, you can access the Redis connection strings from the same page,

6
Figure 6: Connection settings and information for Redis running on Alibaba Cloud VPC

You can use any library that works with Redis and access the services. I tried with StackExchange.Redis library for .NET Core, you can try the same, just make sure you are within the network on VPC before accessing the service.

Apart from this, you can also control how your service is being used and how it spans across all the nodes that you are using, these configurations are also available inside the portal and you can edit them from within the browser too.

7
Figure 7: Server configurations for Redis cache in ApsaraDB

Most policies, like that cache removal upon maximum utilization policy can be configured right from here. Of course, most of the settings have been removed from this list, because of the size of the screenshot that I could take.

Finally, you can also configure the name of your service in the Alibaba Cloud. This can help you recover name collision, or it can help you name the services that can be remembered easily.

8
Figure 8: Editing of the service name for easier discovery on VPC

This way, you can easily control how your services are discovered on the VPC that you have on the Alibaba Cloud.

Now, I believe this is enough for an introduction, as we explored the overall structure of the Redis service provided by Alibaba Cloud's ApsaraDB, and its benefits. We also saw how we can create the accounts and which account would be better for our use case. We will look at how this can be integrated with other services available on Alibaba Cloud, like web apps, or VMs in later post.

0 0 0
Share on

Alibaba Clouder

2,605 posts | 747 followers

You may also like

Comments