Jul 5, 2014

Migrating Web Site to AWS Cloud - A Quick Guide



This is a quick tip to migrate your existing website to AWS Cloud. I assume that you have basic knowledge of AWS Cloud and server side architecture.  This post does not include a discussion of pros and cons of AWS or Cloud services.  Elasticity and Auto-Scaling are two main features of Cloud.  If we don't leverage these feature then there isn't any difference between hosting website in dedicate server or AWS Cloud. You can create EC2 instance and deploy your existing code. It will work perfect, but in this case you cannot apply auto-scale. There is no purpose of migrating web site to AWS Cloud without auto-scaling.

AWS Cloud Service: Following list has description of essential AWS Cloud service.

  1. EC2 (Elastic Compute Cloud)  - It supports operating systems that includes numerous Linux distributions, and Microsoft Windows Server. Amazon EC2 enables you to increase or decrease capacity within minutes, not hours or day.
  2. RDS (Relational Database Service) - Amazon RDS gives you access to the capabilities of a familiar MySql, Oracle, Microsoft SQL Server, or PostgreSql database engine.
  3. S3 (Simple Storage Service) - Amazon S3 provides a highly durable and available store for a variety of content, ranging from web applications to media files.
  4. CloudFront - CloudFront is content delivery network. It can be used to deliver your entire website, including dynamic, static, streaming, and interactive content using a global network of edge locations.
  5. ELB (Elastic Load Balancer) - Elastic Load Balancing automatically distributes incoming application traffic across multiple Amazon EC2 instances.
  6. Auto-Scaling - Auto Scaling allows you to scale your Amazon EC2 capacity up or down automatically according to conditions you define. Mainly It's based on incoming traffic or CPU utilization.
  7. Route 53 (DNS Service) - Amazon Route 53 is a highly available and scalable Domain Name System (DNS)


Architecture:  Let's assume two different architecture, one deployed on dedicated server and another deployed in AWS Cloud. website developed in PHP/ASP/Java with MySql as backend.

Dedicated Server Architecture : This architecture has mainly three components load balancer, application servers and database.



AWS Cloud Architecture: This architecture has Route 53, ELB, EC2, CloudFront, S3, RDS and Auto-Scaling services used.


Migration Phases
  1. Planning – It will include  financial assessment (TOC/ROI), technical assessment, prototype creation or proof of concept, data migration planning and  application migration planning.  
  2. Execution – It will have execution of planning, modification of application source code and testing.
  3. Deployment – It will have deploy application and data migration, AWS Cloud has various tools like AWS Elastic Beanstalk, AWS CloudFormation, AWS OpsWorks, etc.. for deployment and management.
  4. Monitor – AWS Cloud has AWS CloudTrail and Amazon CloudWatch services for monitor AWS resources.

Tips for the developers:  Migrating to AWS Cloud require code and structure changes.  

  1. Migrate MySQL database to RDS,  MySql database can directly migrate (export - import)  to RDS-MySql engine. 
  2. As you are migrating to AWS Cloud, you have more storage options like SimpleDB and DynemoDB.  You can take advantage of these storage services to off load data from MySql . It’s call hybrid approach  - SQL and NOSQL
  3. In dedicated architecture all files, (for eg:- images, videos, etc...)are stored in web space /some folder in server.  In case of AWS Cloud all files (images, videos, etc  ...) should be stored on S3.
  4. In dedicated architecture, all web assets (CSS, JS, Icons, and Images) are stored in virtual directory of web server and web server or application will serve these assets, which is unnecessary on servers.  In AWS Cloud, all web assets (CSS, JS, Icons, and Images) should be stored in S3 and link with CloudFront.
  5. In dedicated architecture, your cron jobs will run on same web server. In case of AWS Cloud, you may require dedicated EC2 instance for cron jobs or you can create schedule EC2 instance.
  6. In dedicate architecture, you may have only application which serves all request. For AWS you can use two separate servers, Web Server (i.e. Apache HTTP Server, Nginx Server, etc...) and Application Server (Tomcat, IIS, etc...)
  7. Few application services are available in AWS Cloud that you can use depending upon the requirement.
    1. Amazon SQS – Amazon Simple Queue Service (SQS) is a fast, reliable, scalable, fully managed message queuing service.
    2. Amazon SNS - Amazon Simple Notification Service is a fast, flexible, fully managed push messaging service.  It also supports push notifications to Apple, Google, Fire OS, and Windows devices.
    3. Amazon SES - Amazon Simple Email Service is a cost-effective outbound-only email-sending service.

Reference

  1. http://aws.amazon.com/whitepapers/migrating-your-existing-applications-to-the-aws-cloud-with-3-example-scenarios/
  2. http://highscalability.com/blog/2010/12/21/sql-nosql-yes.html
  3. http://aws.amazon.com/products/

Jun 27, 2014

Android L Preview API Changes

src: http://developer.android.com/preview/images/l-dev-prev.png

Android L Preview Features

  1. A New Design - Material Design
  2. A New Runtime - ART (Android Runtime)
  3. Enhanced Notifications
  4. Project Volta- Increased Efficiency
  5. Support for OpenGL ES 3.1
  6. Android Extension Pack
  7. Camera API for advanced camera capabilities
  8. Storage - Directory selection
  9. Multiple network connections
  10. Bluetooth broadcasting
  11. NFC enhancements
  12. Scheduling jobs
  13. Enterprise - Managed provisioning
  14. Render PDF as bitmap
  15. Testing and accessibility improvements
  16. Easier switching between input languages
Android L Preview API Changes

TypeAdditionsChangesRemovalsTotal
Packages843051
Classes and Interfaces872320319
Constructors842086
Methods4086917494
Fields754221777
Total1341368181727
The overall difference between API Levels 20 and L-preview is approximately 3.77%.
New Packages
  1. android.app.job
  2. android.bluetooth.le
  3. android.hardware.camera2
  4. android.hardware.camera2.params
  5. android.media.session
  6. android.media.tv
  7. android.service.voice
  8. android.system

Jun 21, 2014

Android Triangle Pager Sliding Tabs

TriangleTabs is extension of PagerSlidingTabStrip

Note: This is not a plug and play library that you can directly import in project and use. Triangle tabs is extension of PagerSlidingTabStrip library. In this article I will explain, how to modify PageSlidingTabStrip library to create Triangle Tabs.
Android Triangle Tabs Video 




Customise PageSlidingTabStrip

Step 1: Import PageSlidingTabStrip library in AndroidStudio.
Step 2: Let add new attribute for Triangle Tabs in attrs.xml (project -> res -> values). This attribute will allow developer to enable / disable triangle tabs.

<attr name="pstsTriangleIndicator" format="boolean"/>
Step 3: We need to modify Java code for Triangle Tabs.Goto source code and Open PagerSlidingTabStrip.java file
Step 4: Declare boolean variable above constructor, for pstsTriangleIndicator attribute.

private boolean triangleIndicator = false;
Step 5: Fatch pstsTriangleIndicator attribute, write following line in constructor

triangleIndicator = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTriangleIndicator, triangleIndicator);
Step 6: Now it's time to draw triangle tab, goto onDraw method and add following code.

Original Code

canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
New Code, conditional code for triangle tabs

if (triangleIndicator) {
      Rect r = new Rect();
      int left = (int) lineLeft + (int) (((lineRight - lineLeft) / 2) - (indicatorHeight / 2)) - 20;
      int top = height - indicatorHeight;
      int right = (int) left + indicatorHeight + 30;
      int bottom = height;
      r.set(left, top, right, bottom);
      Path path = getEquilateralTriangle(r);
      canvas.drawPath(path, rectPaint);
} 
else {
      canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
}
Step 7: This is last step, declare getEquilateralTriangle() function. This function has code for triangle.

public Path getEquilateralTriangle(Rect bounds) {
        Point startPoint = null, p2 = null, p3 = null;
        int width = bounds.right - bounds.left;
        int height = bounds.bottom - bounds.top;

        startPoint = new Point(bounds.left, bounds.bottom);

        p2 = new Point(startPoint.x + width, startPoint.y);
        p3 = new Point(startPoint.x + (width / 2), startPoint.y - height);

        Path path = new Path();
        path.moveTo(startPoint.x, startPoint.y);
        path.lineTo(p2.x, p2.y);
        path.lineTo(p3.x, p3.y);

        return path;
    }

Usage

Step 1: Include the customized library as local library project or you can copy PagerSlidingTabStrip.java, attrs.xml and background_tab.xml in respective folders of your main project.
Step 2: Include the PagerSlidingTabStrip widget in your layout. This should usually be placed above the ViewPager it represents. Noticed pstsTriangleIndicator attribute

<com.kpbird.triangletabs.PagerSlidingTabStrip
        android:id="@+id/activity_main_pagertabstrip"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        custom:pstsTextAllCaps="true"
        custom:pstsIndicatorColor="#FF3F9FE0"
        custom:pstsDividerColor="#FF3F9FE0"
        custom:pstsUnderlineColor="#FF3F9FE0"
        custom:pstsTriangleIndicator="true"
        custom:pstsShouldExpand="true"
        custom:pstsIndicatorHeight="15dp"
/>
Step 3: In your onCreate method (or onCreateView for a fragment), bind the widget to the ViewPager.

// Declar variable 
private ViewPager pager;
private PagerSlidingTabStrip pagertab;
private MyPageAdapter pageAdapter;

// Inside onCreate
pager = (ViewPager) findViewById(R.id.activity_main_pager);
pagertab = (PagerSlidingTabStrip) findViewById(R.id.activity_main_pagertabstrip);
List fragments = getFragments();
pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);
pager.setAdapter(pageAdapter);
pagertab.setViewPager(pager);
Step 4: Compile & Run application



Jun 20, 2014

Microservice Architecture - A Quick Guide

1. What is Architecture (Software)?
Architecture is the fundamental organization of a system embodied in its components (i.e. Web Server, Application Server, Databases,Storage, Communication layer, etc...), their relationships to each other, and to the environment (i.e. deployment environment shared server, dedicated server, cloud deployment, etc..), and the principles guiding its design and evolution.
2. What is microservice architecture ?
Microservice means developing a single, small, meaningful functional feature as single service, each service has it’s own process and communicate with lightweight mechanism, deployed in single or multiple servers.
3. Advantages of microservice architecture ?
  • Each micro service is small and focused on a specific feature / business requirement.
  • Microservice can be developed independently by small team of developers (normally 2 to 5 developers).
  • Microservice is loosely coupled, means services are independent, in terms of development and deployment both.
  • Microservice can be developed using different programming language (Personally I don't suggest to do it).
  • Microservice allows easy and flexible way to integrate automatic deployment with Continuous Integration tools (for e.g: JenkinsHudsonbamboo etc..).
  • The productivity of a new team member will be quick enough.
  • Microservice is easy to understand, modify and maintain for a developer because separation of code,small team and focused work.
  • Microservice allows you to take advantage of emerging and latest technologies (framework, programming language , programming practice, etc.).
  • Microservice has code for business logic only, No mixup with HTML,CSS or other UI component.
  • Microservice is easy to scale based on demand.
  • Microservice can deploy on commodity hardware or low / medium configuration servers.
  • Easy to integrate 3rd party service.
  • Every microservice has it's own storage capability but it depends on the project’s requirement, you can have common database like MySQL or Oracle for all services.
4. Disadvantages of microservice architecture ?
  • Microservice architecture brings a lot of operations overhead.
  • DevOps Skill required (http://en.wikipedia.org/wiki/DevOps).
  • Duplication of Effort.
  • Distributed System is complicated to manage .
  • Default to trace problem because of distributed deployment.
  • Complicated to manage whole products when number of services increases.
5. In which case / requirement microservice architecture best fit ?
When you need to support Desktop, web , mobile, Smart TVs, Wearable, etc... or you don't know in future which kind of devices you need to support.
6. Which products / companies are using Microservie architecture?
Most large scale web sites including Twitter, Netflix, Amazon and eBay have evolved from a monolithic architecture to a microservices architecture.
7. How independent micro services communicate with each other?
It's depend upon requirement, normally developers use HTTP/REST with JSON or Protobuf(Binary protocol) but are free to use any communication protocol.
8. Why is it that everyone are talking about microservices now?
It’s been nearly 15 years since the concept of Service Oriented Architecture really took hold. With the improvement of RESTful web service and JSON as a data interchange format has made it easier than ever to build easily interconnectable services simply and quickly.
9. Presentation
10. Video

11. Picture: Monolithic vs Modular vs Service oriented architecture
Reference:
  1. http://martinfowler.com/articles/microservices.html
  2. http://microservices.io/patterns/microservices.html
  3. http://www.infoq.com/presentations/Micro-Services
  4. http://yobriefca.se/blog/2013/04/28/micro-service-architecture/
  5. http://www.tomakehurst.com/microservices-and-monoliths-is-there-a-third-way/
  6. http://www.infoq.com/articles/microservices-intro

NoSQL - A Quick Guide


NoSQL is buzz word now-a-days among the developers and software professionals.
1. What is NoSQL?
NoSQL database, also called Not Only SQL, is an approach to data management and database design that's useful for very large sets of distributed data.
2. Where to use NoSQL ?
Use NOSQL, When project has unstructured big data that require real-time or offline analysis or web/mobile application. i.e. Social Network app, Analytics app.
3. Advantages and Disadvantages of NoSQL DB.
Advantages of NoSQL
  1. Elastic scaling
  2. Big Data
  3. Ecomomics
  4. Flexible data models
Disadvantages of NoSQL
  1. Maturity
  2. Support
  3. Analytics and business intelligence
  4. Administration
  5. Expertise
4. Category of NoSQL
  1. Column
  2. Document
  3. Key-value
  4. Graph
5. How many NoSQL database are available in market?
More then 110 different (Open Source and Proprietary) NoSQL database available in market
6. If all NoSQL database fall under above category then what is purpose of having lots of NoSQL databases ?
Every NOSQL database has some special feature & functionality which makes it different, Base on the project requirement one can choose NOSQL database.
7. Can I use multiple NoSQL in my project / application ?
Yes
8. List of popular NoSQL database with usage.
Radis: For rapidly changing data (should fit mostly in memory). i.e. to store real-time stock prices, analytics, leaderboards and communication. And replacement of memcached.
MongoDB: When you need dynamic queries, defined indexes, map/reduce and good performance on a big DB. i.e. for most things that you would do with MySQL but having predefined columns really holds you back.
Cassandra: When you need to store data so huge that it doesn't fit on server, but still want a friendly familiar interface to it. When you don't need real-time analysis or other operation. i.e. Web analytics, Transaction logging, Data collection from huge sensor arrays.
Riak: If you need very good single-site scalability, availability and fault-tolerance, but you're ready to pay for multi-site replication. i.e. Point-of-sales data collection. Factory control systems. Places where even seconds of downtime hurt. Could be used as a well-update-able web server.
CouchDB: For accumulating, occasionally changing data, on which pre-defined queries are to be run. Places where versioning is important. i.e. CRM, CMS systems. Master-master replication is an especially interesting feature, allowing easy multi-site deployments.
HBase: Hadoop is probably still the best way to run Map/Reduce jobs on huge datasets. Best if you use the Hadoop/HDFS stack already. ie. Search engines. Analysing log data. Any place where scanning huge, two-dimensional join-less tables are a requirement.
Accumulo: If you need to restict access on the cell level. i.e. Same as HBase, since it's basically a replacement: Search engines.
Hypertable: If you need a better HBase. i.e/ Same as HBase, since it's basically a replacement: Search engines.
Neo4j: For graph-style, rich or complex, interconnected data. Neo4j is quite different from the others in this sense. i.e. For searching routes in social relations, public transport links, road maps, or network topologies.
ElasticSearch: When you have objects with (flexible) fields, and you need "advanced search" functionality. i.e. A dating service that handles age difference, geographic location, tastes and dislikes, etc. Or a leaderboard system that depends on many variables. you can replace your Solr with ElasticSearch.
Couchbase: Any application where low-latency data access, high concurrency support and high availability is a requirement. i.e. Low-latency use-cases like ad targeting or highly-concurrent web apps like online gaming (e.g. Zynga).
9. Can I have video tutorial to learn more about NoSQL?
Sure, Watch following video..


Reference & More reading...
  1. http://en.wikipedia.org/wiki/NoSQL
  2. http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis
  3. http://www.dzone.com/mz/nosql
  4. http://www.nosqlweekly.com/
  5. http://nosql-database.org/