In business software applications, the domain objects (entities) are used to represent the business domain. As the application grows and adds more business logic, the service layer, mappers and other patterns gets applied. This sector has held promise for many software developing companies, and has often been touted as the future of work. Often this leads to domain object becomes bloated and the related components become huge & un-maintainable.
CQRS solves the common problem of having a bloated Domain objects. The domain objects get bloated largely because of bounded context. The series of contexts which makes developers think that a single domain object is sufficient to handle all the related things. For example, a large Invoice object for handling Invoice, Shipment and handling change of address for customer . But in reality, these contexts (invoicing, shipment and change) need not be related to same Invoice entity.
What is Command, Query Responsibility segregation (CQRS)?
In order to simplify the Domain objects, CQRS proposes to have two types of domain entities.
those serving the command (ordering/assertion services) – For example, SaveCustomer, CreateInvoice, ShipProduct etc
those serving a Query (request) – examples include GetCustomerAddress, SearchCustomer etc
With this separation, the complexity (number of fields, methods) of entities used becomes simplified. And hence the Data mapper layers & the service layers becomes more simplified.
Where can I use CQRS?
Largely complex system: Applying CQRS on a simple CRUD operation based system is a over kill. When there is a domain heavy system, like banking and financing systems, LOB applications where business logic, lots of boundary conditions are heavy. Where it makes DDD (Domain driven design) provides high value.
Situations where you will apply Microservices, Eventual consistency and Event Sourcing. When we have separation of concerns using CQRS, the microservices becomes much simpler to design and maintain. With Event sourcing we are focused on getting the data (query) from other related sources and is what CQRS propagates.
Final words
CQRS is a carefully thought out pattern for simplifying & solving large and complex systems.
Below is the top 100 Agile websites list published by AgileChamps team. The process followed to identify top 100 sites is:-
Identified few core keywords used for Agile.
These keywords are used against the majority of top search engines.
The websites coming on first few pages are identified. Approx. 1200 plus websites are shortlisted.
Identified Alexa Rank for all of them.
All the websites under 15 million ranks are reviewed individually.
The websites which are heavy centric on Agile are marked and rest are removed.
At this point, top 200 websites are shortlisted for final review and research. The top 100 are picked after spending a good time with each and every website.
The list may not be 100% perfect but it should be close as there are chances that some of the good websites on Agile are missed. If you think, you have an Agile Blogging site which is not listed here, please do mention in the comment section with Alexa rank and we would include that in below list.
In this video, Jatinder talks about Six fundamental principles for improving web application performance. He also talks a lot about how we go about Decreasing CPU time and increasing parallelism on the client machine to achieve faster web performance.
While I went through the video, I captured all the tricks he talks about. And thought will be useful for others while they watch it. Please find below the tricks.
Quickly respond to network request
Avoid 3XX Redirections (63% of top websites use redirect)
Avoid Meta refresh
Minimise Server time for Requests
Use Content distribution Networks (CDN)
Maximise concurrent connections.
Reuse connections – don’t sent connection close.
Know your other servers – you are only fast as your weakest link
Use window.requestAminationFrame(renderLoop) for Animations
Know when your application is visible (document.hidden, Visibilitychange (event))
Conclusion
The web optimisation is not easy and needs exhaustive, deep look and hopefully this check list helps while optimising your pages. Enjoy coding high performing applications. If you have more tips please provide them in the comments.
Microservices is a really becoming a famous architectural pattern that most of the new software written these days, just apply them. One of the most important differentiation between the traditional web services and micro-services pattern is the amount of common stuff across different subject areas. This calls for a discussion on how Eventual Consistency pattern is mandatory for successfully implementing microservices.
The micro frontend if gaining lots of popularity. You can read about microservices principles and micro frontends at
Generally, in a micro-service pattern, the API’s are split into small subject areas. For example for a CRM application, the subject areas are
Customer information – like name, address, email, phone
Appointment information – which customer, salesperson, when, where
Relationship management – sales/manager, what products, interests
Campaign data – offers, deals etc
Then micro-services are built for each of the subject areas. The microservices are logically and physically separated from each other. ie there is no sharing (code, database, component etc) between any of these micro-services of these subject areas. Pictorially its looks something like this.
Applying Eventual Consistency Pattern
In Micro-services, there is no data that is shared across the micro services. In order to synchronize the data across these isolated storages of these services, we need to apply the eventual consistency pattern. You can read more about applying the pattern correctly here. The simpler way we can achieve consistency across these micro-services is through Event Sourcing pattern.
Event Sourcing
Event sourcing is a process of capturing application state changes in the form of events. An example of events are customer created, customer updated, Deal created, etc. Other systems listen to these events and they take relevant action. You can read more about event sourcing here.
Conclusion
Event sourcing is the new way of storing changes to systems and help in making micro-services eventually consistent. These patterns together form well maintainable, reliable and scalable systems in the modern world.
In the previous article we looked at how to do Test Driven Development (TDD) while doing the XP (Extreme Programming). In XP, the implementation of the tasks are done in the steering phase of the iteration planning. One of the tenets of the steering phase is “functional tests are run”. In this article we will see how to create functional tests using Behavior driven development (BDD) and its benefits.
Following are the some of the benefits of automated functional tests.
Functionality experienced by the User is tested
Saves testing time for the developers
Test in every environment (Dev, QA, Stage) without much effort
Generates confidence in every stake holder
Tools required for doing BDD in .Net
There are various tools available to do BDD in .Net. I have listed few of them below
SpecFlow is one of the most popular tools used in the .Net/C# community. And in this blog lets use the same. The tool comes as a Visual Studio Extension and can be downloaded directly from VS.
Creating a SpecFlow Project
Once SpecFlow extension is installed, the template required for doing BDD will be installed.
Create a simple “Class Library” Project in Visual studio
In the project, create a SpecFlow Feature file
Selecting the test framework
Before we Create/execute the scenario, we need to wire the SpecFlow with a compatible test framework. To do that we need to make changes to the app.Config file of the project.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<unitTestProvider name="xUnit" />
</specFlow>
</configuration>
In this example we are using XUnit as the testing framework. SpecFlow supports a series of testing frameworks and more details can be found here.
Creating the Behavior
Now, let us look at how to create a functional test using behavior driven approach. Let’s consider the following story while creating a POS (point of sale) application for a super market.
“As a Supermarket POS app developer, i would like the API to Give the total amount while billing so that I can wire up API against the UI.”
Let’s write the Behavior required in order to implement the above API requirement .
Feature: SuperMarketProductsAPI
As a Supermarket Biller
i would like the API to
Give the total amount while billing
@SmokeTest
Scenario: Find the total amount while billing
Given Shopping cart is filled with all the items required by consumer
And Campaign information for the month is available in the system
When I pass the cart to create bill API
Then the total bill amount should be calculated
The above specification is written using the custom language (testing DSL) create by the specflow.org. (Please read about what is DSL here.)
There are 2 parts to the above Specflow specification
Feature – Denotes bigger context (description/story) of the application
Scenario – Specific workflow or behavior of the system under the feature. Each scenario has the following sub-parts
Given, And – describes what we already assumed available
When – The specific action which will trigger the workflow/behavior
Then – expected behavior
Creating step definitions
When we run the unit test corresponding to the above test we it will fail as there are no definitions corresponding to the above scenarios.
Now Right Click on the feature file and select “Generate step Definitions”
You will see the pop-up like below, select “Generate” and then “Save” the file.
The file will have the details about “what SpecFlow should do when test is executed”.
using System;
using TechTalk.SpecFlow;
namespace SuperMarketFunctionalTests
{
[Binding]
public class SuperMarketProductsAPISteps
{
[Given(@"Shopping cart is filled with all the items required by consumer")]
public void GivenShoppingCartIsFilledWithAllTheItemsRequiredByConsumer()
{
ScenarioContext.Current.Pending();
}
[Given(@"Campaign information for the month is available in the system")]
public void GivenCampaignInformationForTheMonthIsAvailableInTheSystem()
{
ScenarioContext.Current.Pending();
}
[When(@"I pass the cart to create bill API")]
public void WhenIPassTheCartToCreateBillAPI()
{
ScenarioContext.Current.Pending();
}
[Then(@"the total bill amount should be calculated")]
public void ThenTheTotalBillAmountShouldBeCalculated()
{
ScenarioContext.Current.Pending();
}
}
}
When you build the project and execute the test corresponding to this, it will fail. This is because none of the parts of the test (given, when, then) are having implementation.
Writing code to make it work
Now that the behavior has been created, we are good to validate that with the team and implement the code/functionality corresponding to the requirement. Of course using best coding practices like TDD 🙂
Making the behavior test pass
In order to make the behavior test pass we need to write the implementation in the “Step Definition” file.
namespace SuperMarketFunctionalTests
{
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net.Http;
using TechTalk.SpecFlow;
using Xunit;
[Binding]
public class SuperMarketProductsAPISteps
{
Product P1 = new Product { Name = "test1", Cost = 5 };
Product P2 = new Product { Name = "test2", Cost = 10 };
ShoppingCart cart;
List<Campaign> campaign;
Bill bill;
[Given(@"Shopping cart is filled with all the items required by consumer")]
public void GivenShoppingCartIsFilledWithAllTheItemsRequiredByConsumer()
{
cart = new ShoppingCart { Products = new List<Product> { P1, P2 } };
}
[Given(@"Campaign information for the month is available in the system")]
public void GivenCampaignInformationForTheMonthIsAvailableInTheSystem()
{
campaign = new List<Campaign> { new Campaign { product = P1, discount = 1 } };
}
[When(@"I pass the cart to create bill API")]
public void WhenIPassTheCartToCreateBillAPI()
{
var client = new HttpClient();
var response = client.PostAsync("http://myapi.supermarket.com", new StringContent(JsonConvert.SerializeObject(cart))).Result;
var output = response.Content.ReadAsStringAsync().Result;
bill = JsonConvert.DeserializeObject<Bill>(output);
}
[Then(@"the total bill amount should be calculated")]
public void ThenTheTotalBillAmountShouldBeCalculated()
{
Assert.True(bill.totalAmount == 14);
}
}
}
Once the code is there we can see the behavior test pass.
Conclusion
BDD is very powerful way of ensuring high code quality in conjunction with business requirement. In Extreme programming (XP) , BDD is considered to be a very important practice where functional tests are mandated to run at least once during the iteration. Is BDD/Functional tests helping your team/business in achieving success or not ? Do let us know your thoughts.
This is the second post in the Getting started with MEAN series where we start looking at the Node ecosystem for stable web application frameworks for our application. A brief glance through the Express framework showed that express by itself would be time consuming start off with from scratch. On the other hand, the Express.js website links to a number of frameworks built on top of Express. This looked like a good place to start exploring.
Going through the list of frameworks mentioned there, however, we quickly noticed that a number of options were either targeted only (or primarily) towards APIs, lacked sufficient documentation for our needs, or did not appear to have a sufficiently large community behind them. Mind you, the assessment wasn’t entirely objective, as I did have previous experience with generator angular fullstack.
Why generator-angular-fullstack
Generator angular fullstack is a Yeoman generator that provides an application skeleton as well as sub generators that allow the developer to quickly scaffold various UI and API components. The generator supports a number of customizations through questions asked before generating the app. The ones I found most useful were:
Client Side
Html templating : HTML, PUG (previously Jade)
Angular Router : ngRouter, ui-router
Stylesheets : css, stylus, sass, less
CSS frameworks : bootstrap (with the option to include UI Bootstrap)
Server Side:
Scripts : javascript, Typescript
Databases : none, Mongodb, SQL
Authentication boilerplate
oAuth integration with Facebook, Twitter and Google Plus
Socket IO integration
Phew! That was a lot of options built into the generator itself, stuff that teams and products usually like to customize according to their convenience. This by itself is a strong reason to select the framework, because none of the other frameworks that we evaluated came anywhere close in terms of customizability and out of the box functionality. The generator also comes with built in hooks to deploy your application to Heroku or Openshift, although I found that part to be a little broken (more on that later)
A lot of things have changed though, since my last experience. For one, the guys over at generator-angular-fullstack added support for Typescript. Typescript in fact, is a superset of javascript, but brings a number of enhancements (including transpile time type safety) to the table. On the other hand, the generator still works with Angular 1.x, although the alpha version does support Angular 2. But then, working with the alpha version for a project needing quick turnaround times didn’t sound like an exciting thought.
Anyway, coming back to getting started with the application.
Getting Started
Installing Yeoman
npm install -g yo
Installing the angular fullstack generator and its prerequisites
npm install -g yo gulp-cli generator-angular-fullstack
On a side note, please read node-gyp’s installation guide before going any further to get the application to run successfully. Node-gyp is required to compile native drivers for each platform and on windows, there are a couple of different ways to support the compilation process. Personally, I was able to get option 2 on the link mentioned above working (see: “Option 2: Install tools and configuration manually”)
Initializing the App
Finally! Coming down to the crux of the matter. Initializing the app
Run : yo angular-fullstack
The installer asks a number of questions about customization, including the ones mentioned above, and once the installer has completed, you have a fully functional app (with authentication if you selected it during install) ready for you to work on.
Running the app is as simple as running : gulp serve
You just need to make sure that if you selected a database, it is running on your local box so the node API can connect to it. If the DB is not found, the application will simply crash, but you already knew that would happen 🙂
Stay tuned for the next article about the getting familiar with the code generated by the Yeoman generator
What is the difference between System.Array.CloneTo() and System.Array.CopyTo()?
What is the difference between an interface and an abstract class? Give examples of their use in real life?
Can you use “this” with the static class?
What is the primary difference between “read-only” and “constants”?
What is a garbage collector? Can we force the garbage collector to run? Is that guaranteed that it would run?
What is public, static, void, and main?
Can we execute multiple catch blocks written for the same try block?
What is the difference between Finalize() and Dispose() method?
What is a sealed class in C#? Explain with examples?
What is the difference between a HashTable and a dictionary? When to use what? Give an example of each?
What is “out” and “ref” parameter in C#?
What is “protected internal” in C#?
What is a “finally” in exception handling? How does it differ from finalize?
What is generics?
What is the difference between a connection pooling and an object pooling? How and where do you set the connection pooling parameter? What is the default value?
What is multiple inheritance? Is it allowed in C#? How do you achieve that?
What is boxing and unboxing? Give examples of each?
What is a copy constructor?
What is a static constructor?
What is the difference between overriding and overloading? Give examples?
What do you mean by virtual method?
What types of comments are used in C#?
What is abstraction, inheritance, polymorphism, and encapsulation?
What is the relation between data hiding and encapsulation?
“Know what you want to do, hold the thought firmly, and do every day what should be done, and every sunset will see you that much nearer to your goal.” Elbert Hubbard
GOAL – A goal is a description of a condition one wishes to achieve. It is the desired result or possible outcome that a person or a system envisions and commits to achieve.
If there is no goal, there is no direction. “Being happy” is not a goal because it does not describe the specific condition. Instead, “I would travel to Europe this year” is a goal.
The GOAL should be SMART. This acronym extends to Specific, Measurable, Attainable, Realistic and Timely. This is indeed very powerful tool while hardly used.
S – Specific
If you don’t express your goal in specific terms, it is very difficult to achieve. Moreover, you will never know whether you have achieved your goal or not.
Examples
Ambiguous/Vague – I want to lose weight.
Specific – I want to lose 5 kg in next 90 days.
M – Measurable/Meaningful
You must have concrete criteria to achieve your goals. You should be able to measure your result or outcome to ensure you are on track. The goal will be really meaningful when you attach motivation to it.
A – Achievable/Attainable
Goals should be motivating and challenging while do ensure that it’s not virtually impossible. The moment you define your goals and start working on them, it starts coming closer. Things get easier. Attainable doesn’t mean choosing very simple goals. The tough goals stimulate you to do more and expand your comfort zone.
R – Realistic/Relevant
The goals which are not realistic, you are highly unlikely to achieve them. Although nothing is impossible but the exceptions are rare. For instance, if you decide to go for ACP certification with little agile knowledge, assuming you will read 5 books in 5 days, the chances are fat that you will have a success.
T – Timely/Timebound
It is critical to specify a timeline for achieving your goals. If the goal is for the long term, break them down into smaller multiple goals to hit your ultimate goal. This would keep you motivated throughout the journey. For instance, you want to rank number one blogging site for Agile in 24 months, you can target to get into first 1000 in 6 months, 100 in a year, 10 in 1.5 years and eventually number one in 2 years.
Guidelines
Give a deep thought, identify your goals, discuss if needed.
Write them down clearly.
Review them regularly.
Track your progress.
Update your goals as required.
Take the complete ownership of your goals.
Short term goals need to be more realistic. The long term should be broken down into multiple short term goals.
The “Law of Attraction” principle works very well with your goals. If you constantly keep looking at your goals every day, then the chances of achieving them become very high. According to “Law of attraction”, if you can convince yourself of something, the whole world support you to achieve that. The self-motivation/self-realization/self-acceptance of accomplishing a goal is more important than putting an effort has been proven many times.
The people will treat you the way you treat yourself. If you think, you would get promoted and you convince yourself that it would happen, it is very likely that it will happen. In order to convince yourself, you should set SMART goals. This will be one of the inputs for “Law of Attraction” to work. You must have noticed that if you want something desperately and constantly focusing on that, you will just get it. In the process of desperation, you actually work on convincing yourself.
You must be logged in to post a comment.