27 July 2016

Preface to Microservices

As the pace of IT technology evolving and its dynamic nature increased, more scalable and durable architecture for solution become relevant. As time went by we came across single tier standalone applications to distributed computing models like client server architecture, N-tier application architecture, Service oriented Architecture to build stable and durable and maintainable solutions. However many of these architecture was having limited life span due to its co-related bindings or tightly coupled nature. Lot of these architecture has limitation to scale par with the usage needs or resilience. Time has reached to re-think of the sustainability of architecture that avoid complete rewrite with technology changes and support patching and resilience for durability and scaling.
Microservices is an approach to application architecture in which a large application is built as a suite of modular services. Each module supports a specific business goal and uses a simple, well-defined interface to communicate with other modules. Because of the modularity this architecture not only increase the reusability also support to scale out nature, maintainability and sustainability.

Principle behind Microservices
Microservices are based on Scale Cube principle for scalability which emphasis on the Y axis Scaling – An approach of modularizing a program based on its verb nature or noun characteristic of functions. For example “Login mechanism” is a verbal function, “Payment gateway” is a noun function.
Microservices also emphasis is Single Responsibility Principle (SRP) which help to decouple a unit function and give it an identity and hence it can be reused.
Another principle is based on the light weight interfaces that the services use to communicate with the external components or users.
Yet another principle to ensure the identity of a Microservice is Self-contained system. An autonomous, isolated unit that includes its own data, logic, and UI.

Scalability
Other than Y axis Scaling X and Z axis scaling also are considered in Microservices architecture to bring out the higher potential of scaling and application rigidity and high availability.
X Scaling is a way of scaling by replication of the same instance in a kiosk way so that the requests will be load balanced.
Z Scaling is a way of data sharing-based approach. When using Z-axis scaling each server runs an identical copy of the code. In this respect, it’s similar to X-axis scaling. The difference is that each unit is responsible for only a subset of the data. Many a time a routing mechanism is used to route the query to the specific subset of data.

Single Responsibility Principle
SRP is derived as the principle behind object oriented programing the way how a class is derived. The intention behind using SRP in Microservices to design the services with maximum modularity so that it can be reused , scale and maintain than an interrelated service, this Microservices are modular, compose able and fine-grained units that do one thing and one thing only.

Light weight interfaces for communication
An asynchronous is the preferred communication mode for Microservices as it won’t create an IO block in comparison with a synchronous communication. However there will be situation where synchronous communication is unavoidable like the database will usually have to be synchronous in the sense that it happens within the request-response cycle. Remote calls are more expensive than in-process calls, and thus remote APIs need to be coarser-grained.
REST APIs are mostly used in Microservices interfaces. HTTP and REST synchronous calls should be minimized between Microservices because of its co-related nature. Advanced Message Queuing Protocol (AMQP) for asynchronous communications are also widely used between Microservices.
Message bus technologies like RabbitMQ and Apache Kafka for asynchronous communication between Microservices are also widely used. In case the message-passing is done on the same host, then the containers can communicate with each other by way of system calls, as they all share the same kernel.

Containerization
Containers is an operating-system-level virtualization method for running multiple isolated systems (containers) on a control host using a single kernel. The Container concept was first introduced in Linux. Containerization is Light Weight Virtualization, which will eliminate wastage of resources compared to normal server virtualization. As Containers will share resources, it results in optimize resources utilization and void latency due to OS booting.  Each Container will have its own IP and network settings. Containers extend the decoupling, separating software from the underlying hardware in micro service architecture.
Containers decouples software from the underlying hardware, bringing us portability and speed not seen before in VM-based solutions. Containers are easily packaged, lightweight and designed to run anywhere. Multiple containers can be deployed in a single VM. Microservices encourages to decouple our software into smaller functional pieces which are expected to fail, bringing us agility and resilience. Thus bringing a blend of Microservices architecture with Containerization will result in better resilience and modularity for maintenance. 
A composition of Containers can logically form an application. Application orchestrating multiple containers will achieve the desired output.

Some best practices while Microservices Design
Asynchronous communication- Avoid IO blocks using asynchronous communication as much as possible. Using synchronous communication might cause IO blocks in case the serving service is not available to complete the loop of communication. Using the asynchronous pattern the services are more decoupled compared to the synchronous pattern and which preserves the autonomy of the service. Ultimately, the goal is for your service to be available to the end-user even if other services that are part of the whole system are offline or unhealthy.
Clean Separation of Stateless and State full Services- Microservices scale better when they are stateless. In such circumstances where we need to use state full services we have to keep persistence layer or data caching mechanisms.
Avoid Sharing and Avoid Host Affinity and Reduce dependency- When one or more containers rely on the same library, it may be tempting to share the dependencies by centrally configuring them on the host. This model introduces complexities in the long run. It not only it brings host affinity, but also breaks the Continuous Integration Continuous Deployment pipeline. Also need to consider to keep only the required library for the unit of function to work.It is almost impossible to reduce the dependency due to the atomicity of Microservice, but the design should take care to reduce the co-related interdependency as much as possible.
Well defined APIs – The APIs should be well defined for entry and exit, also should have proper exception handling by the service.
Self-Registration and Discovery Mechanism using central registry- A central registry is maintained for looking up all available services. Central service registry is used to handle registration. The registry plays a critical role in orchestrating Microservices. Netflix Eureka, Consul and Apache Zookeeper are examples of commonly used registries for Microservices.

Benefits of Microservices Architecture
RAD-From a project engineering perspective. When the different components of an application are separated, they can be developed concurrently independently and faster.
Resilience - Rather than relying upon a single virtual or physical machine, components can be spread around multiple severs or even multiple data centers and support failovers and hence continuity.
Scaling-Rather than scaling up with bigger and more powerful machines, or just more copies of the entire application, you can scale out with duplicate copies of the heaviest-used parts.
Polyglot over Single Stack-One advantage of using Microservices is the ability to choose the best of breed OS, languages, runtimes and libraries. For example, With Microsoft adding native container support to Windows, it is also possible to mix and match Linux containers with Win32 and .NET containers within the same environment so that .net as well as java programs or shell scripts together can orchestrate an end to end application.
Code Maintainability-Each micro service is an Independent unit of code which is configured with identity in configuration management system. This makes it possible to deploy newer versions of services without disrupting the application.

Challenges
Basically there are two categories of problems arising with moving to Microservice patterns. One is software architecture mindset/pattern related problems, e.g. how do we define a Microservice, how big or thin should it be, how communication handled, etc.
The other is Testing, deployment and operations production related problems. The concepts like DevOps are supportive to address the later to a greater extend. 

20 January 2014

Provider Hosted App in SharePoint 2013

Create a windows azure empty web site
Down load the publishing profile (we will be using this to publishing setting to publish the app to azure)
Create a new SharePoint 2013 app in Visual Studio.
Visual studio will create app project and azure web application project in this solution.
The next thing required is to create the Client Id.
Client Id and Client Secret is used to connect Window azure web sites / azure cloud services with Office 365 App.
 In the SharePoint site go to _layouts/15/appregnew.aspx to create client ID , Client Secret and register the app.
The following fields are there in a form , Appid and App Secret are created by clicking the button beside the text box. Title App Domain(will be the windows azure domain you used to create the windows azure web site) and Redirect Url(this will be the full url including default.aspx starting with https://) need to be provided.
AppId,App Secret,Title,App domain and Redirect Url
And then register the new app.
The next thing is to set the client ID in the app manifest and web application config file.
In the web.config we also need to put the client secret.
Note that to put the full url in the Startpage.
We also need to remove the appsettings before publishing to ensure than we will be providing the credential on the fly.
GetContextTokenFromRequest is the key method to get the Context token and to create the context.
TokenHelper class have methods to pass Context  token and get the Refresh token and to pass the refresh token to get the access token.
All this token handling is encapsulated using GetClientContextWithContextToken method of TokenHelper Class.
Once you get the context you can communicate to the web and the SharePoint Objects.
To publish we need to import the profile we downloaded from the azure site after we click publish.

30 December 2013

Videos in SharePoint 2013

There are two ways to deal with videos in SharePoint 2013. There is a content type called video in SharePoint 2013.When you upload the video to this content type it will store as BLOB in the content database. You can store up to 1 GB videos in the content database. The Advantage of storing in the content database is security like other content type. But more video you store more will be the cost of storage as the blob using SQL server for storage.
The other way of storing videos is as a link to other physical locations. The security of the videos needs to be explicitly handled in this case.
When you store the videos in the SharePoint the blob cache need to be optimized for smooth streaming, Like Size the BLOB cache to a certain percentage of the total size of unique videos viewed in a week, this can be 60-80 % of total size of unique videos viewed. To optimize performance, do not place the BLOB cache on the same drive as the system drive, and ensure that the drive where BLOB is cached have enough space.
When the videos are stored in the external locations to the SharePoint like a web severer (IIS server) or a media streaming server the streaming is performed by the external location's source.
With a single WFE with 12 GB ram, 4 core processor and 8 core 16 GB DB server, it supports 400 concurrent video viewing in the acceptance level. As no of WFE increases it support a minimum 200 more additional smooth streaming. The no of smooth streaming is not linear but shows exponential increases by adding additional WFEs.
With a IIS Server same as the configuration of WFE 600 smooth concurrent streaming can be expected. By using media streaming services and media servers this can gain boosted. Bit Rate throttling is another extension to ISS to increases the bandwidth while streaming videos.

26 August 2013

Content Search Web Part to roll up content in SharePoint 2013


SharePoint 2010 has a big limitation with Content Query Web Part to roll up content and we have to do good effort of work around as Content Query Web Part was limited to the Site Collection. In SharePoint 2010 we used the Content Query Web Part which helps us to see content instantly without waiting for the next crawl.

This drawback is eliminated in SharePoint 2013 using Content Search Web Part. Content Search Web part is available in the Web part>Content Roll Up>Content Search. This web part will allow you to create your own query easily and display the results the way.

Change Query in the Property Page will allow you to design your own query. The “Query Builder” has a nice UI that helps us to configure the query. “Switch to the Advanced Mode” in the “Query Builder” will provide more option to narrow down result.

A “Test Query” Option is available with the “Query Builder” which will provide a Preview of Result for whatever you configured.

Now the question is why we need Content Query Web Part in SharePoint 2013 since we are having Content Search Web part. To understand this we need to understand how this both web parts work. CSWP work based on the search index, made by Crawl. The result will be displayed is the data is crawled. CQWP does not depend on Crawl. Again this is less significant since as SharePoint 2013 supports continuous crawl. CSWP will not search minor versions whereas CQWP does.(I am not sure this is a bug and will be rectified later). From a design perspective CSWP no longer requires XSLT, HTML, or JavaScript.

14 August 2013

SharePoint 2013 Geo Location Field & Map

SharePoint 2013 Provide a new field type (column type) called Geo location. This field is used to enter the longitude and latitude data. SharePoint out Of the Box will provide an association to a Bing map to the entered Geo Location. A list Created with Geo Location field will also can have a Map View in which a map will be displayed aside the list with the pinned entered Geo location. When you hover the Geo Location in the list the corresponding location will be highlighted in the map.

The Site column contain a field called “Location” , But this field will not be the right thing to add for Geo Location. We cannot add Geo Location field using SharePoint 2013 UI.
Use the following code to create a Geo Location field to a List.

private static void CreateGeolocationField()
{
  // Replace site URL and List Title with Valid values.
  ClientContext context = new ClientContext("<site url>");
  List myList = context.Web.Lists.GetByTitle("list Title");
  myList.Fields.AddFieldAsXml("<Field Type='Geolocation' DisplayName='Location'/>", true,   AddFieldOptions.AddToAllContentTypes);
  myList.Update();
  context.ExecuteQuery();
}
 
You can also use power shell command for the same.
A map view of the list can be created using UI.

12 August 2013

SharePoint 2013 Device channels - Branding and Content based on Devices and Browsers

Device channels in SharePoint 2013 allow changing the look and feel depending on the browser or the device. This feature helps to implement corresponding Master Page or Page layout designed for the end browser or device.

Device Channels can be implemented only for the publishing sites, which make sense since on publishing sites only we can publish different master pages.

We have to create a “Device inclusion rule” to identify an end browser or Device. The Device inclusion rule that need to be included can be referred from the site “whatismyuseragent.com”.
To implement device channel navigate to Settings > Look And feel > Device Channel and Add a new entry. “Device inclusion rule” is the vital data here. Name, Alias and Active are other columns here once all this entries are added and saved you will get an option in the Master pages settings to select a new master page for the entry you just created.

We can choose to include or exclude portion of any page layout in a channel this will help for including or excluding content based on browser/devices.
Thus Device Channel is a significant feature in SharePoint 2013 that helps to render the appropriate look and fell and content based on browsers and devices.

15 May 2013

Image Renditions in SharePoint 2013 Save Size and boost performance.


Image Renditions Is a facility available in SharePoint 2013 for having different sizes of the image for different content holders? Different renditions can be created like full size, thumb nail etc. Image rendition also helps to adjust the picture to which part to display. This facility will help to reduce the size of the image to be downloaded at the client and hence optimize the performance. Image rendition also helps to store the file in the reduced space in the content database since only one copy of the file is actually getting stored. We need to enable BLOB cache before you can use image renditions.

A  Rendition ID can be used with the image url like this “?RenditionId=n” to assign different rendition.