Sunday, February 23, 2014

Urgent vs important

Off late I have realized that its very important for one to understand the Graph between Urgent and Important.

There are four combinations:-

1. Urgent and important
2. Not Urgent but important
3. urgent but not important
4. Not urgent not important

To manage our time properly and to prioritize stuff in work as well as personal life we should be able to categorize every task one of the above category. Henceforth, Its very easy to make your decisions.

Somebody has put this up perfectly -

“The most effective people make their important things, your urgent ones. The most ineffective people do the exact opposite.”

1. Urgent and important : This category is for critical tasks. Which needs to be resolved ASAP. We should avoid things to fall under this category as this is life is full of deadlines and possess high risks.

2. Important but not urgent: A good leader or visionary always keeps his/her tasks in this category. As it's a safe zone. A good manager foresees and senses any possible task which can be categorized as 'Urgent & important' and addresses them. We should not procrastinate tasks which falls under this category as there is high chance of them to become urgent and important. (Highly recommended)

3. Urgent but not important : This are things which should be handled if time permits and scheduled after urgent and important.

4. Not urgent and not important: This are useless things which should not be focused. One to stay away or procrastinate these things until he/she has free resources.


I found an below image online, which can explain Urgency vs importance more :


Programming Windows Workflow Foundation 4.0

It has been long, like 3 years since I wrote my last blog post. I am little nervous :).

Think of an online task you do in your day to day life and it should have a workflow backing up. Eg. you buy movie tickets online (Its a client side workflow, you go to ticketing site -> chose tickets -> confirm -> pay).  Other workflow is server-side workflow which is a background task. Eg. when you buy a product on Amazon. Steps, Chose a product -> pay -> A server side workflow should kick off which contacts actual seller, calculates estimated delivery time, add order details in your account, send confirmation email to buyer and other individual tasks.

Today I want to write about Windows workflow foundation 4.0 (WWF). There are other workflow frameworks like Oracle offers, Sharepoint workflow etc.

But I personally liked this workflow framework. WWF a framework used to perform work intensive sequence of tasks (known as activities). Always remember, workflows are used to "Just Do Work".
Eg. Do X -> Check Y-> See P -> Send A and for 1 million users. Your workflow in workflow designer might look like:


I have been working on WWF since couple of months and I am amazed with the power of this framework. With this you can :-
1. Run independent tasks/Activities in parallel
2. If you have created a share point farm your workflow can run on multiple machines in parallel.
3. It can be triggered by a workflow or a timer job
4. Create custom activities to implement business logic.
5. Set up concurrency of workflows
6. Call external methods and use those results in workflow
7. Automate a sequential set of tasks.

I would like to talk about performance of Windows workflow. Since it runs on the application server. Doing things wrong/inefficient can slow down the entire server and eat up the processor and clog the database.

I want to talk about few things which you should keep in mind while programming with Windows workflow:
1. Performance: Its a important aspect of every piece of code. But it becomes very important in case of workflows. Eg. you have to give discount to user on your product based on the sales, page hits and other parameters in 1 million products on your website. Calculating discount for individual product should be very efficient, it should take less than a second by your workflow. Workflows should not run more than couple of hour.  Keep batching in mind. If you are reading an item from database , processing it and writing into database try batching stuffs. Divide 1 million item in batches, read a batch of 10000 items -> process them -> save 10000 items together. Batch size is critical can be best explained by :




2. Logging: Log every failure, successes, high importance in proper category for telemetry and support purpose.
3. Scalability: What if you start dealing with 100 million products after supporting 1 million products. Keep this in mind. In that case, divide your products with category, run workflow for individual category. Don't do any unnecessary operation in your workflow. which can slow down your workflow by many folds.
4. Modularization: Try to break your methods as small as you can. So that it can be used by some other activity ,help you in unit testing and improves the maintenance of the code.
5. Memory: Keep memory leakages in mind. for eg. C# has a built in garbage collection, but always Dispose objects which are derived from IDisposable interface. When your workflow is running keep track of memory used by the workflow process in the task manager. It should increase and become constant. If ,the memory should keeps increasing during the life of the workflow, its an alarming situation.
6. Activity flooding: Decomposition of every tasks to an activity might look fascinating. But creating every activity has a cost(creating activity and deleting activity ) by the workflow. We should not create 3 activities for a million object. That means if the cost of Create + Delete of an activity is 0.01 sec then you can save 20k seconds = 5 hour by creating 1 activity to do all 3 things together.

Remember workflows are made to "Do work" . If you have some base cases, which will exit the workflow in between, check that condition before the workflow is kicked off.

Let me know if you have more pointers to improve programming in WWF.
Disclaimer: Ideas/Views mentioned above are purely personal and learnt with Experience/reading. Feel free to correct me.