Tuesday, February 9, 2016

Applications of Blockchain

Applications of Blockchain:

What can you do using Blockchain


  • Manage contracts in a smarter way by not depending upon one server or organization. With smart contracts, you can directly deal with your partners and store contracts and rules in blockchain network Smart contracts
  • Tracking products: You can track a product exactly where it originated from - say a food item can now be tracked where it was farmed from how it was maintained and this information can be stored in public.
  • Ownership details: You can store information like I am willing to buy your house for 1000$ on this date in block chain - it will be stored in this public ledger for everyone to see - you cannot go back and change this to 500$ or the date. 
  • Storing public records such as land & property titles, marriage certificates, death certificates, vehicle registrations, notarized documents etc.,
  • Identity: Identiy a person, thing by verifying data against the person. For example Onename.com is a Blockchain id registrar that links users and validate by using them using different ways – visit onename.com for more information. https://onename.com/deiveehan
  • Store identification records such as driver licences, ID cards, passports and voter registrations.
  • IOT – Internate of things:
    • Device to device transactions, for example the device such as television or washing machine can have its own identity and can make re-order, make transactions on its own. Who owns what device can be stored in Blockchain.
    •  Of course, Money transactions: Blockchain can help you in transferring money to another country as it will be faster and cheaper. With this technology it will be faster and cheaper. Bitcoin is already an implementation of Blockchain which helps users to transfer quickly without a middleman.

Some interesting links:

  • Lazooz – block chain based ride sharing platform.
  • Nasdaq share trade using Blockchain – read more
  • Smart contracts - youtube
  • IBM Adept’s POC demo shows how do they implement this technology to make devices do smart payments – View demo
  • Couple got married on Blockchain – read more
  • How block chain will change the real-estate market – Read more
  • Crowd funding using Blockchain: Blockchain based crowd funding: Blockchain-based crowdfunding is similar to traditional crowdfunding, however, collected funds are accounted for and tracked via a Blockchain – Read more



Blockchain - basics

A decentralized application is an application where the data required for processing is not owned by government or companies, but by individuals from different parts of the world, who get paid for lending their processing power to run those programs. 

Some of the main characteristics of a decentralized application include: 
  • Data may not be owned by a single company or an organization. 
  • Tamper proof: Once a transaction happens on a decentralized application, no one should be able to alter the data, and even if they do, it is not affected by that as many nodes does the processing. 
  • Data cannot be controlled, censored by a company or country. 
  • Data may not be limited to only monetary transactions, but can have any data such as ownership details. 
  • No need to trust a single node in the decentralized application. 


So what is Blockchain?

Blockchain is a technology that helps developers build decentralized applications – It allows two people or thing who does not know each other to trust and make transactions with each other. 

Blockchain is a distributed database that contains shared record of transactions that cannot be censored, tampered with, erased or duplicated. It’s a new way to store and record transactions. These transactions can be certificate of ownership of an item, bank's financial transaction, person's will information etc.

This distributed database is collaboratively maintained by peers on the network, called nodes. A node is a machine where the validation & processing happens. Individual nodes verify the sender and the transaction and approve them. This removes the need for a third party to intermediate. 

These nodes are stored in public which means this is not owned by a country or an organization. Users lend their processing power to process these data, in turn get their incentive for their processing power. 

The transactions involved can be anything from certificate of ownership of an item, bank's financial transaction, person's will information etc. 
  
Blockchain can be thought of as a public ledger which holds all important transactions that is stored in a distributed way. You can do a lot more with the Blockchain than exchange value. Once a transaction appears on the Blockchain, it is impossible to deny that it has happened. Hence it cannot be censored, tampered with, erased or duplicated. It is a technology that fundamentally influences the way trade ownership and trust has been functioning. 

Blockchain works well even when some of the operators are dishonest, some nodes run slowly or tampered. 

We will look more on block chain applications in the next article. 

Sunday, January 3, 2016

SAML explained

You might have seen lot of web sites / services you access requesting you to login with an login page that you have used before.

To understand SAML, you might need to understand the following terms.

Identity Provider (IP): The company / enterprise holding the user credentials.
Service provder (SP): The company providing the service - say salesforce.
User: the person going to use the service.

Traditionally the credentials are maintained by Identity provider, but the credentials are also maintained in the Service provider so that whenever the user tries to access the SP he is authenticated within the service provider itself.
You might have seen in some sites where they ask you to register with a username and password to access the service.

Now the problems of using this approach is:
- the service provider have to maintain the user credentials even though the user credentials are in the Identity provider.
- the user has to remember different user credientials for the IP and the SPs.
- The identity provider has to follow a cumbersome process of disconnecting the access to the SPs whenever the user goes out of the company or his roles changed.

How its solved.

Typically, the user requests access to the Service (SP), the SP redirects him to the Identity provider (IP), the user gets his userid and password validated from the Identity provider.
The Identity provider provides a token (a file which contains user information - but not password) to the service provider.
The service provider now knows that its a valid user and allows him to access the service.

Now using this approach, the SP dont have to maintain password, the user has to remember only one password, and its easy for IP to manage user information and he has control over the services.

Now what is SAML: 
SAML is the token we talked about. Its the XML based data format for exchanging user information between the Identity provider and the service provider.

When the user is authenticated by the IP, the user can then access the services with the token provided by the IP.

How long can the user access the service with the token provided by IP, what if the user goes out of the company.
The token issued by the IP also has the expiry time. Whenever the SP receives the token, it is valid only till the time, after that the service provider redirects back to the identity provider. The user has to get another token with a revised expiry time on the token.


What does SAML describe:
- describe the structure of the data.
- explains how the data should get transported between the IP and SP


How does communication happens between the IP and the SP:

In the above picture you can see the sequence flow how the user is authenticated and he is allowed to access the resource in SP. 

Friday, January 1, 2016

AWS Glacier - Overview

Glacier storage service is meant for storing archival data. It is best suited for data that is not frequently accessed.

It is priced very low when compared to S3. Accessing the object in glacier is very slow - for example, the checkout job can take several hours for data to be available.
Integrates will with S3 life cycle.
With glacier you dont have to worry about the server provisioning, you can store as much data as you want - as usual.

A single archive can be as large as 40 TB.

You can configure glacier to be like "Write once read many" to prevent losing data by mistake.
You can also set the data retrieval policies such as maximum retrieval rate. you can also see which users have accessed the vault over the last one month, or identify who deleted the data.

You can use AWS console or use the AWS SDK APIs to store data into Glacier.
you can also setup policies in S3 so that every month data is archived back from S3 to Glacier. AWS Import / export product can be used to accelerate moving large amount of data.

Pricing is based on how much data you are planning to store and how much time you are planing to retrieve. Data transfer costs and PUT requests also matters but its low.

For example, if you want to store 100GB of data with no retrieval, it might approximately cost 7 cents per month.
You can use the AWS calculator to calculate how much it is going to cost you based on your data requirements.


Amazon S3 - overview

S3 is a storage product from AWS to help users store documents such as pdfs, pngs and any other files. An object in S3 can be called as a single file.

Characteristics: 
- an object can be up to 5TB.
- you can encrypt data before saving into S3 and decrypt before downloading into your desk.
- supports unlimited data upload and multi-threaded uploads.
- High availability: Automatically stores data in multiple zones within your region.
- you can add policies to a bucket, for example you can say after 2 months of data upload, you can configure to move the data to another storage such as glacier.
- supports versioning of objects within S3, which means when you accidentally delete an object, you can recover by accessing old versions of the object.
- secured storage, which means you can be sure that only you can store or set priveleges that only you can access the data.
- you can store as much data you want, it will scale based on your needs.

What operations you can perform using S3. 
- CRUD operations on Bucket.
- you can choose your region/zone you want to store the data and use S3 APIs to store the data.
- you can send event notifications whenever someone uploads a data into an bucket.
- Can be integrated with other AWS services such as "whenever an object is loaded into a bucket, you can send the data into Kinesis".
- use S3 as a backup storage or host static files for your web page.
- perform disaster recovery of your systems by storing backup images in S3.
- host static web sites or files.

S3 pricing: 
- Storage cost: You pay approximately $0.03 for every GB for the first 1 TB
- Request pricing:
you pay $0.004 per 10,000 requests for all GET requests.
You pay $0.005 per 1,000 requests for all PUT, COPY, POST requests, delete requests are not priced.
- Data transfer pricing:
Data transfer in to S3 is not charged
Data transfer OUT to same region is not charged.
Data transfer OUT to another region or over to internet is charged, first 1 GB transfer is free, after that it will be charged at 9 cents per GB.

You can use the AWS calculator to approximately determine how much it will cost for the services you choose based on the data you provide.
http://calculator.s3.amazonaws.com/index.html

Full pricing information can be found here - https://aws.amazon.com/s3/pricing/

How do you operate on S3: 
- use the AWS console to operate on S3
- use AWS SDK, supports different languages such as Java, .net, python, php, nodejs, ruby. You can also use AWS mobile SDK to directly upload data into S3 from the mobile.

S3 FAQ: https://aws.amazon.com/s3/faqs/

Monday, November 23, 2015

CloudFoundry – Getting started


This article helps you getting started on cloudfoundry. This does not explain on the cloudfoundry concepts.

Step 1: Create an account in pivotal cloudfoundry. 
                You can create a 2 months free subscription account from pivotal cloudfoundry services web site https://run.pivotal.io. An organization as the name specifies – can be your company name, project group or so.
The space is nothing but the environment you wish to create, you may want to have a development, qa and production spaces. In short applications are hosted in spaces (environemnts) and spaces belongs to an organization.



Step 2: Create a simple spring application, you can also create in Grails, Ruby etc., You can use maven, gradle as the build tool.
                You can use spring boot to create a simple application. Please refer http://ndeiveehan.blogspot.com/2015/11/spring-boot-getting-started.html to create a new spring application.

You can also create in other languages as Cloudfoundry offers other buildpacks.
Once created, you can generate the war or jar using the maven command.

Step 3: Login to cloudfoundry and create required organization and spaces.
From you PC, login to cloudfoundry using the CLI tools.
cf login -a https://api.run.pivotal.io

Enter your credentials to login.



Step 4: Deploy your application.
You can push the apps in the following ways:
- Use the Cloudfoundry CLI tool.
- Use cloufdoundry eclipse plugin.
- Use a build plugin to integrate deployment as part of your build tool.
 but this article shows you how to push application using the CLI tool.

Now issue the following cf command.
cf push springbootfirst -p target/springbootfirst-0.0.1-SNAPSHOT.jar
               
 This command uploads the spring jar file to the cloudfoundry site and starts the server. 

Step 5: You can now access the web application in the following web url:




Now there is a lot more you can do using CF tool such as:
-          Configuring your own domain instead of cfapps.io.
  • Scale up an application.
  • Deleting an app, renaming it, start or stop an application.
  • View logs for an application
  • Enable ssh for an application.
  • View services from the market place.
  •  Create, update organizations, spaces, buildpacks etc.,
  •  Perform user administration on organizations / projects.



See you in the next article on cloudfoundry. 

Spring boot - Getting started

Spring boot - Getting started


This article explains how to get started on Spring boot. Assuming you already have JDK, maven and eclipse installed in your PC, lets get started. 


Step 1: Create a simple maven project in eclipse.
Step 2: Create the following parent definition in pom
       <parent>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-parent</artifactId>
              <version>1.3.0.RELEASE</version>
       </parent>

Add the following dependencies
              <dependency>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-starter-web</artifactId>
              </dependency>
Spring boot starter web dependency takes care of loading required jars for the web such as spring web etc., No more hassles on the need to remember the spring jars and version names.

Step 3: Create a simple web controller
@RestController
@EnableAutoConfiguration
public class SampleController {

       @RequestMapping("/")
       String home() {
              return "Hi Buddy";
       }
      
       public static void main(String args[]) {
              SpringApplication.run(SampleController.class, args);
       }
}
The EnableAutoConfiguration annotation informs boot to automatically configure required annotations based on the jars that you have added in your application. Cool isn’t it.
Run the Above Sample Controller as a java application
What just happened. When did I start the web server ??
Actually Spring boot takes care of that. When you actually run SpringApplication.run, it internally runs a web server and then loads the controller into that server.




Step 4: Invoke the controller in the web browser: 


Simple and easy to develop without having to worry about dependencies or the server. 

Now if you don’t want to add the parent pom for whatever reasons like you want to add your own project parent pom or so, you can add the following dependencies.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.3.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>

You may also want to add the following to package your project as an executable jar.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>