Microsoft Service Fabric is an application platform that simplifies building and deploying microservices-based applications to provide organizations with reliable, scalable and agile applications whether they are running in Azure, on-premises or on any other cloud platform. Azure Service Fabric offers health monitoring features and provides various built-in programming models to simplify developing cloud-based applications.
NCache is an in-memory distributed caching solution that provides an extremely scalable approach for your .NET and Java applications. NCache also provides support for various cloud platforms such as Service Fabric and Kubernetes in Azure, Amazon EKS and Red Hat OpenShift. It improves the performance and scalability of your cloud applications in peak transaction loads. The following diagram shows the deployment of NCache in Azure Service Fabric:
NCache can be deployed with Azure Service Fabric in the following ways:
In order to deploy NCache in your Service Fabric cluster, following are the main components that need to be deployed within your cloud applications:
NCache Discovery Service is a stateless reliable Web API that gets the real-time information about the IP addresses of the NCache servers to provide the information to the NCache clients. With this information NCache creates cache handles for the clients that can help the clients perform operations on the clustered cache. The NCache discovery service consults with the Service Fabric naming service to get the IP addresses of the containers on which NCache servers are running.
<ServiceTypes> <StatelessServiceType ServiceTypeName="NCacheDiscoveryType" /> </ServiceTypes> <CodePackage Name="Code" Version="1.0.0"> <EntryPoint> <ExeHost> <Program>NCacheDiscovery.exe</Program> <WorkingFolder>CodePackage</WorkingFolder> </ExeHost> </EntryPoint> ... </CodePackage> <ConfigPackage Name="Config" Version="1.0.0" /> ... </ServiceManifest>
This service is a container service that uses the Docker image of NCache. This service allows NCache servers running within containers to communicate with one another across hosts so as to form the cache cluster by using the Open configuration mode and exposes the ports required for communication.
<ServiceTypes> <StatelessServiceType ServiceTypeName="NCacheServiceType" UseImplicitHost="true" /> . . . <ContainerHost> <ImageName>alachisoft/ncache</ImageName> </ContainerHost> . . . <Resources> <Endpoints> <Endpoint Name="cache-management" Protocol="tcp" UriScheme="tcp" Port="8250" CodePackageRef="Code" /> </Endpoints> </Resources>
This service is used to expose the NCache Web Manager for performing the management and monitoring operations in the cache. This service uses the same image that the NCache cluster service uses. The reason to separate the NCache management service from the NCache cluster service is that in Open configuration mode, host-to-port mapping is not allowed. NCache Web Manager needs to be accessed by providing the host port and for this another service known as NCache management service is created with NAT mode.
<ServiceTypes> <StatelessServiceType ServiceTypeName="NCacheWebManagerType" UseImplicitHost="true" /> </ServiceTypes> . . . <ContainerHost> <ImageName>alachisoft/ncache</ImageName> </ContainerHost> . . . <Resources> <Endpoints> <Endpoint Name="web-management" Protocol="http" UriScheme="http" Port="8251" Type="Input" CodePackageRef="Code" /> </Endpoints> </Resources>
This service allows the containers on multiple nodes to communicate with one another. This service is used to acquire the client-side counters for the monitoring of the cache cluster.
All these services create successful NCache deployment inside your service fabric cluster for creating a cache cluster and then performing monitoring and management operations on it. This service communicates with the NCache discovery service which in return provides the client with the IP addresses of the containers.
<ServiceManifest Name="ClientContainerPkg" . . .> <ServiceTypes> <StatelessServiceType ServiceTypeName="ClientContainerType" UseImplicitHost="true" /> </ServiceTypes> . . . <ContainerHost> <ImageName>ncache/apps:sfclient</ImageName> </ContainerHost> . . . </ServiceManifest>
NCache can also be accessed by the service fabric services when on a virtual machine not included in the service fabric virtual machine scale set. In this case, NCache service discovery is not required and the applications can be furnished with the IP addresses of the NCache servers. To access NCache from outside the Service Fabric cluster, you can provide the correct IP addresses in your client.ncconf or through the CacheConnectionOptions API provided by NCache. This allows seamless communication of microservices with NCache outside the Service Fabric cluster.