Friday, February 27, 2015

RASPBERRY PI

Did you know?
 The Raspberry Pi sprang out of a desire by colleagues at the University of Cambridge’s Computer Laboratory to see a return to the days of kids programming inexpensive computers. The rise of expensive PCs and games consoles put paid to the BBC B, Spectrum and C64 generation of home programmers, leading to applicants for computer studies courses lacking the necessary skills.
The basic concepts behind the Raspberry Pi were to make it as affordable as possible, supply only the basics and provide it with a programming environment and hardware connections for electronics projects. The Pi is a series of credit card-sized single-board computers, which runs a modified version of Linux called Raspian with Wheezy Raspian being the preferred option for newcomers to the device. Raspian runs directly on an SD card and provides a command-line interface for using the operating system.

The original Raspberry Pi and Raspberry Pi 2 are manufactured in several board configurations through licensed manufacturing agreements with Newark element14 (Premier Farnell), RS Components and Egoman.

Fig: Raspberry Pi (Model B)

Programming the Pi
There are two programming languages supplied by default with the Pi: Scratch v1.4 and Python. They both have shortcut icons on the graphical desktop. Scratch was designed by Lifelong Kindergarten Group at the MIT Media Lab as a firststep in programming. It uses tile-based language commands that can be strung together without having to worry about syntax. Commands are split up into easy-to-understand groups and dragged onto the scripting area. Sounds, graphics and animation can be added. Projects can be saved or uploaded to the Scratch website and shared for remixing by other users.
The other language is Python v3.2.3 which starts with a Python Shell. Python is an interpreted language, where commands are read and implemented one line at a time. The high level commands and data structures make it ideal for scripting. The previous version of Python is still quite popular and has more development aids, so is also supplied. The icons for these are IDLE 3 and IDLE, which stands for Integrated Development Language for Python.

The Pi Store
www.store.raspberrypi.com/projects
The Pi Store isn’t just home to apps and tools to help you use your Raspberry Pi. There’s also a selection of home-grown video games to get your teeth into, that are developed by the Raspberry Pi community.

Monday, February 9, 2015

CQRS (Command Query Responsibility Segregation) Pattern

Command–query separation (CQS) is a principle of imperative computer programming. It was devised by Bertrand Meyer. It states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both. In other words, methods should return a value only if they are referentially transparent and hence possess no side effects.

Command Query Responsibility Segregation (CQRS) applies the CQS principle by using separate Query and Command objects to retrieve and modify data, respectively. CQRS Pattern segregate operations that read data from operations that update data by using separate interfaces. This pattern can maximize performance, scalability, and security; support evolution of the system over time through higher flexibility; and prevent update commands from causing merge conflicts at the domain level.

CQRS is a pattern that segregates the operations that read data (Queries) from the operations that update data (Commands) by using separate interfaces. This implies that the data models used for querying and updates are different. The models can then be isolated, although this is not an absolute requirement.
Compared to the single model of the data that is inherent in CRUD-based systems, the use of separate query and update models for the data in CQRS-based systems considerably simplifies design and implementation.
The query model for reading data and the update model for writing data may access the same physical store, perhaps by using SQL views or by generating projections on the fly. However, it is common to separate the data into different physical stores to maximize performance, scalability, and security; as shown in Figure.
The read store can be a read-only replica of the write store, or the read and write stores may have a different structure altogether. Using multiple read-only replicas of the read store can considerably increase query performance and application UI responsiveness, especially in distributed scenarios where read-only replicas are located close to the application instances. Some database systems, such as SQL Server, provide additional features such as failover replicas to maximize availability. Separation of the read and write stores also allows each to be scaled appropriately to match the load.

When to Use this Pattern
This pattern is ideally suited to:
  • Collaborative domains where multiple operations are performed in parallel on the same data.
  • Use with task-based user interfaces (where users are guided through a complex process as a series of steps), with complex domain models, and for teams already familiar with domain-driven design (DDD) techniques.
  • Scenarios where performance of data reads must be fine-tuned separately from performance of data writes, especially when the read/write ratio is very high, and when horizontal scaling is required
  • Scenarios where one team of developers can focus on the complex domain model that is part of the write model, and another less experienced team can focus on the read model and the user interfaces.
  • Scenarios where the system is expected to evolve over time and may contain multiple versions of the model, or where business rules change regularly.
  • Integration with other systems, especially in combination with Event Sourcing, where the temporal failure of one subsystem should not affect the availability of the others.
This pattern might not be suitable in the following situations:
  • Where the domain or the business rules are simple.
  • Where a simple CRUD-style user interface and the related data access operations are sufficient.
  • For implementation across the whole system. There are specific components of an overall data management scenario where CQRS can be useful, but it can add considerable and often unnecessary complexity where it is not actually required.

Event Sourcing and CQRS
The CQRS pattern is often used in conjunction with the Event Sourcing pattern. CQRS-based systems use separate read and write data models, each tailored to relevant tasks and often located in physically separate stores. When used with Event Sourcing, the store of events is the write model, and this is the authoritative source of information. The read model of a CQRS-based system provides materialized views of the data, typically as highly denormalized views. These views are tailored to the interfaces and display requirements of the application, which helps to maximize both display and query performance.
Using the stream of events as the write store, rather than the actual data at a point in time, avoids update conflicts on a single aggregate and maximizes performance and scalability. The events can be used to asynchronously generate materialized views of the data that are used to populate the read store.
Because the event store is the authoritative source of information, it is possible to delete the materialized views and replay all past events to create a new representation of the current state when the system evolves, or when the read model must change. The materialized views are effectively a durable read-only cache of the data.