Spring Boot Microservices
Spring Boot Microservices
Secure Infrastructure
API Lifecycle
a. Understanding of undertaking
b. Capture internal API requirements
i. Developer community requirements (APIs, SDK, sample code)
ii. User stories (architectural styles within requirments)
c. Market/Competitor analysis
d. Planning for long term: infrequent versioning
e. Assess organization impact
f. Business/identity/price model considerations
i. Public vs private vs semi private, LSUD Vs SSKD
ii. Service Tiers (integrate, orchestrate)
iii. SLAs
g. Security requirements
2. Design
a. Codify Requirements
b. Define developer experience
c. Design API
i. Lean API first if applicable
d. Validate & Collect Feedback
i. Tooling for testing /collaboration
e. Documentation drafts
3. Development
4. API Operation
a. Stack Security
b. Orchestration and microservices
c. Scaling
i. Tier and SLA monitoring
ii. DevOps
d. User Management
i. Managing client Ids
e. Billing and commerce considerations
5. Governance
a. Policy Application
b. Policy Layering
c. Managing API Access
d. Enforcement Points
i. API Key
ii. Rate Limiting /throttling
iii. User-level security
iv. App Security
v. Access Control
a. Dev Marketing
i. LSUD VS SSKD, Internal vs Extrernal
ii. Gamification
iii. Hackathons
iv. Intellectual property
b. Onboarding
i. Credential acquisition
ii. Tier Assessment
c. Dashboard
i. Performance
ii. Availability
d. Beta Access
e. SDKs
f. Documentation
i. Code samples
ii. Tutorials
iii. App Showcase
iv. Interactive console
v. Mock APIs
vi. Discoverability
vii. Changelog
viii. Security primer
ix. Great status, codes, support and documentation
g. Evangelism & Constant dialogue
i. RSS
ii. Blogs
iii. Forums
iv. Emails
v. Social Media
Go mobile
Discover new revenue streams and model
Innovate
Digital Transformation
Microservices
Bill Payments
Transaction History
Fund Transfer
Intra Bank Transfers
Transfer Money between customers own wallet (POST)
Transfer Money to a Paylah Wallet (POST)
Transfer Money to external wallet( POST)
Retrieve status of fund transfer (GET)
Inter Bank Transfers
Transfer money to pre registered payee account (POST)
Adhoc transfer (POST)
Retrieve status of fund transfer (GET)
Scheduled Transfers
Retrieve List of scheduled transfer (GET)
Cancel a schedule transfer request (POST)
Limits
Payees
Real time payments
Transaction Analytics
Rewards
Retrieve List of Reward Accounts (GET)
Retrieve Reward Point Balance (GET)
Retrieve Rewards points Transaction history (GET)
Redeem Rewards as vouchers (POST)
Redeem Rewards as miles (POST)
LOANS
Mortgage Loan Application
Retrieve List of Mortgage Loan Application (GET)
Retrieve Mortgage Application Details (GET)
Retrieve List of Mortgage Loan Applicants (GET)
Search for Mortgage Applications (GET)
Initiate New Mortgage Loan Application (POST)
Cancel Mortgage Loan Application (POST)
Declare Applicants Credit Facilities (POST)
Update Mortgage Loan Application Details (POST)
1XX : Informational
o :200 :OK
o :201 : Created
o :202 : Accepted
o :204: No Content
3xx: Redirectional . Clients requests are redirected to different server to the different endpoints to
fulfil client request.
Features
-Web
-JPA
-externalized configuration
In earlier days, For deploying a web application say in a Linux box, the way it used to work is forst I
would need to install the Linux box, then install java on it and then I would need to install a web
server , So I would need to install either tomcat, weblogic or websphere and then I would take my
application WAR and deploy it. This is the usual way we used to deploy stuff.
With Sping boot comes a concept called embedded server, what we do now is we package our
server, so we can package tomcat along with our application JAR, So I can include Tomcat server in
my application JAR. So I don’t need to install it on the Linux box.
So all that I need to do, on the Linux box is if I have java installed that’s sufficient. I can go ahead and
run my application. I don’t need any other server installed on the Linux box.
In the world of Micro Services this makes a huge difference. And also, Spring boot provides a number
of production ready features. Spring boot provides monitoring for your application through
something called Spring Boot Actuator.
For example, we can find out how many times a particular service is called. We can find out how
many times a particular service failed and also can check whether the application is up and running
or not.
All these features comes built in. And another important feature that Spring Boot provide is
externalised configuration. The configuration of applications varies between different environments.
Our configuration from dev different from our config in production. Spring boot provides these
features built in. You can simply create property files matching a simple naming convention and
that’s it and you are ready with externalised configuration. Spring boot also provides support for
different profiles.
These are some of the important goals and features of Spring boot.
The idea behind this step is to understand the big picture of Sping boot. What is it? And What it is
not and what are the important features
Earlier,
We needed to decide, what frameworks and versions to use. I would want to use Sprint MVC and
Spring Security web, Spring Security Config. I would want to use Jackson databind because I want to
do some binding and validation.
I would want to use JSTL and I would want to use Hibernate validator and also for logging I would
use want to add in log4j. We had to decide what dependencies to add in to our projects. Not only
that we needed to decide the versions of them as well.
Sometimes this 5.0.2 final version might not be compatible with some other version of Spring MVC.
So we needed to decide what are the comparable versions and start using them. Choosing the
frameworks to use and which version to use is a major decision that we needed to make when we
were not using Spring Boot.
We needed to implement default exception handling and we needed to create a complete spring
configuration file.
We needed to define the component scan and then we would need to configure a view resolver to
redirect the views to a JSP. To implement internationalization, we needed to implement a message
source and also a locale resolver and in addition to that we needed to configure our web.xml as well.
We needed to configure the dispatcher servlet in web.xml so that it can handle all the requests and
act as a front controller, we needed to configure the Context configuration location in here and we
also needed to configure the Spring Security. We needed to configure the filter for it and make sure
it intercepts all the requests.
There is a lot of work that we would need to fo to get a simple web application up and running. We
configured dependencies, dependency version, Spring Configuration for internationalization, logging
and a lot of other stuff. All these stuff which we looked at in this specific step is the kind of stuff
which we don’t need to do with Spring Boot. Spring Boot would automatically provide all that stuff
for you, so that you can really concentrate on developing your business logic.
All these stuff we saw in this specific ex would be replaced by a simple starter project called Sprint
Boot startup Web in combination with Sprint Boot Starter Security. Just the combination of these
two starters would eliminate the need for a lot of configuration that we looked at these specific
steps earlier.
For creating Spring boot project go to Start.spring.io
For creating a simple restcontroller with a URI like \books and I would want to return a few hard
coded books…Since Tomcat runs on port 8080 by default…URI would be something like
http://localhost: 8080/books
Understanding AutoConfiguration
We have the spring boot application where we have the @SpringBootApplication annotation. The
annotation at SpringBootApplication indicates that this is a Spring context file. That No 1.
Component Scan is one of the important features of Spring where it would start automatically
scanning these classes in this package (com.in28minutes.springboot.basics.springbootin10steps) and
in this subpackage for any beans. So we have added in an annotation @RestController. This is one of
the annotations which is scanned for. So this would be registered as a component. So the
bookcontroller would be registered as a bean and it would be managed by the Sping Framework.
There are three things that are essentially done by @SpingBootApplication as explained earlier.
Now if we want to look at auto configuration in depth, SpingApplication.run method is used to run is
used to run a Spring Context. So we are giving Spring context as an input to it and it would be able
to run that. The run method also returns a application context and we can have it run through loop
of beans avl.
Springboot looks at
Based on these, Spring boot provides Springboot provides basic configuration needed to configure
the application with these frameworks. This is called AutoConfiguration
The core problem Spring framework solves is testability, if you don’t define proper dependencies
then your applications are not testable. The most important feature is dependency injection. The
Core of Spring Framework is the IOC – Inversion of control
Spring framework takes control of all the beans and their dependencies. That’s basically what the
Spring framework cares about. Spring framework is all about defining beans, putting your
@component, putting your @service and things like that and also defining your dependencies
@autowired and things like that and also defining how to find your beans.
Component scan for example. That’s basically the core problem that Spring framework solves the
problem of dependency injection.
It helps you to build loosely coupled applications. Loosely coupled applications can be easily unit
tested.
Other than that Spring framework also solves problems like plumbing code….say if you needed to
use jdbc….u need to write boiler plate code and exception handling..which is not required in spring
framework
Spring MVC is concerned with developing web applications. Spring MVC provides a simple way of
developing web applications. One of the great thing about spring MVC is the separation of concerns.
Dispatcher Servlet is concerned with just the basic front controller part. There is a model and view.
There is a view resolver which is concerned just with resolving a view name to the physical view.
With these kind of simple concepts, Spring MVC makes it very easy to develop your web applications
as well as your restful services.
Whether you are developing web applications or REST services with Spring Boot you are using Spring
MVC framework. That’s the spring web MVC framework.
Can we bring more intelligence into this? When a spring mvc jar is added into an application, can we
auto configure some beans automatically?
How about auto configuring a data source if hibernate jar is on the classpath?
How about auto configuring a dispatcher servlet if spring MVC jar is on the classpath?
Sping-boot-starter-web is the preferred starter for Spring Boot to develop web applications as well
as Restful web services.
When I add in spring-boot-starter-web I automatically get spring mvc, I automatically get validation.
Validation the default implementation for Java validation API is hibernate validator. So I get that as
well and I get Tomcat and also I get starter-json. Starter JSON is more for RESTFUL webservices.
We saw that when we actually invoke the RESTFUL web service the conversion to JSON
automatically happen.
If we look at the code, we just returned bean back. So in the bookscontroller, what we are doing is
we are just returning a list of beans back. Hoe does it automatically convert to JSON? That’s done
through the starter. The starter JSON brings in JSON binding into the picture.
Basically when you look at all starter projects, they have a set of dependencies that are already
defined. And these dependencies are automatically provided to our project.
So when I add in Sping-boot-starter-web, I get all these dependencies. So you’d see that I am getting
Jackson for handling all the JSON stuff, you’s see that I am getting Tomcat so that I can run the
application in Tomcat. I’m getting hibernate validator and validation API for doing the validation. I
am getting this spring framework because I have a dependency on Spring Web and that could have
dependency on Spring framework.
And also I would get logging frameworks as well because the logging frameworks are by default
defined in the spring boot starter. So Spring-boot-starter is one of the dependencies in Spring Boot
Starter Web.
So if you open pom.xml for it, you will find that this the default starter and this is where everything
inherits from. So any starter that you would use in spring boot, it inherits from Spring-Boot-Starter
and you would see that these are the dependency and Spring Boot framework. This has a
dependency on Spring Boot auto configure. That’s how we get autoconfiguration…dependency on
logging…spring core….YML is one of the configuration languages that Spring Boot supports…so we
have snake YML in here…..
Spring-boot-starter-test enables you to write unit test and integration tests as well….In pm.xml..it
has a denation on the auto configured for Spring Boot test and it ahs dependencies on Junit
framework, Assert J…Also Mockito…Mockito is the default mocking framework that comes along
with Spring Boot.
And also have a dependency on the spring-test-framework which is useful in writing unit tests for
spring
Another important starter which is frequently used is spring- boot-starter-data- JPA. JPA is kind of
interface for hibernate. So JPA defines how ORM applications or ORM frameworks should work.
ORM is object relational mapping. Lets now add ina dependency on Spring Boot Starter JPA.
You would now see that there would be a lot more Maven dependence which would come in.
Before JPA
JDBC
Spring JDBC
myBatis
MyBatis removes the need for manually writing code to set parameters and retrieve results. It
provides simple XML or Annotion based configuration to map Java POJOs to database
JPA vs Hibernate
Hibernate understands the mappings that we add between objects and tables. It ensures
that data is stored/retrieved from the database based on the mappings.
Hibernate also provides additional features on top of JPA. But depending on them would
mean a lock into Hibernate. You cannot move to other JPA implementations like Toplink.
Web Service – W3C Definition
3 Keys
XML, JSON
Different Groups/Types of Webservices
SOAP
REST
Simple Object Access Protocol (specific way of building web-services), XML as format for sending
request/response.
SOAP defines a specific XML request and response structure
SOAP
Format
o SOAP XML Request
o SOAP XML Response
Transport
o SOAP over MQ
o SOAP over HTTP
Service Definition
o WSDL
CHALLENGES
For new applications it is much more difficult. We might not have right- business knowledge
to define the bounded context
It is a evolutionary process, it is not something which we will get right the first time… try and
follow domain driven design…try to identify the right boundaries for the microservices based
on the knowledge we have at that point in time.
The important thing to understand is that as we gain knowledge we should put that
knowledge back into the microservices into deiciding what is the right boundaries for these
microservices.
3. DYNAMIC SCALE UP AND SCALE DOWN: Establishing the technology to do that. The loads on
different microservices will be different at different instances of time and at particular
instance I might need two instance of microservice and later point in time I might need 10
instance of the microservice. So I should be able to bring the new instances of microservices
up and bring down older instances of microservices when they are not really needed. All this
with dynamic load balancing because when there is one instance of microservice 1 there are
4 instances of microservice 2 then I would want to distribute the load between all the
instances of microservice and if there are 4 instances of microservices 2 coming up, then I
would want to ensure that all the new ones are also being used to the fullest.
So we need the ability to dynamically bring in new instances and also to distribute the load
among the new instances.
5. PACK OF CARDS: If microservices are not well designed microservice architecture can be
like pack of cards what do I mean basically that in microservices architecture we have one
microservice calling another, another calling another..there will be certain microservice
which will be fundamental for the whole thing and if that microservice goes down then the
entire application might go down. So it is like pack of card. Therefore it is very important to
have fault tolerance in our microservice
1. Adapt new technology processes very easily. When we build application as a combination of
microservice which can communicate