Applications get old, and technology moves fast. Overtime, adding or modifying functionalities might become as expensive as re-coding everything all from scratch. But rewriting a complete website and its functionalities it’s hard if we want to minimize the risks of breaking existing functionalities and specially when this application fits in a ecosystem and interacts with other pieces of software and teams.
In this session, you will learn how we moved from a legacy java monolithic website using scala PlayFramework, AngularJS, Elasticsearch and MongoDB, how we built a multi service and REST oriented architecture, which were the technical and human problems we encountered and how we managed to solved them.
48. Front End
• Sass built in with play
• AngularJS, popular, community, experience
• Foundation, solid and easy CSS framework
49. Database
• Flexible schema
• Document oriented makes sense with CVs
• Low transactions
• Application code rules the database schema
– Already the case with SQL Server
• No DBA*
– We rule the database as dev
51. Status
• +10 years of candidate data
• Crucial for business
• Cannot fail really, C A N O T F A I L !!
52. Strategy
• Start migration as soon as possible
– Started in April – Mai
• Migrate data incrementally
• Verify as much as possible
• Legacy ID
53. Akka Actors
• One actor per data
• Concurrence execution when possible
• Handle updates for the crucial moment =>
between SQL Server Stop and MongoDB Up
59. Model choices
• ++ reads / -- writes
• Stable Reference data *
– Sometimes sectors can change…
• Low and non risky transactions
– Ex : user deletes account
61. Unit Testing
• Using Specs framework
• Using Mockito
– Not as useful as in Java
• Some tests are not necessary
– Constructors, Builders … Scala Type Safe and
Immutability
62. Testing the Front END
• Unit testing JS with Karma
• Selenium
– Very fragile tests
– Proxy Nightmare
– Endless navigator problems
– Just vital tests after production
64. Testing the REST API
• No Mocking MongoDB
• Using Embedded Mongo
• Start and Stop Mongo once for every test
– DRY data is a hard part
https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo
67. SCALA USER GROUP
This section is specially dedicated to the Madrid Scala User Group.
Thank you to Nouhoum Traoré who spoke about it at scala.io in Paris
74. Single responsibility Object :
Controllers
@Singleton
class AccountValidationController @Inject() (
accountValidator: AccountValidator) extends Controller {
def validateAccount(token: String) = Action.async { request =>
accountValidator.validate(token).map {
case Some(account) => Ok(Json.toJson(account))
case _ => UnprocessableEntity(Json.toJson(InvalidToken))
}
}
75. Single responsibility Object :
Services
class AccountAuthenticator @Inject() (...)
class AccountValidator @Inject() (...)
class AccountCreator @Inject() (...)
class AccountSettingsUpdater @Inject() (...)
81. The (original) Team
• 3 Developers and a Product Owner
– Legacy + Backend + Scala
– Full-Stack
– Java + Backend + MongoDB
• From 5-10 years of experience
• People who are able to leave their confortable
coding zone
• Want to communicate
102. DI Framework vs Cake Pattern
@Singleton
class LoginController @Inject()
(accountAuthenticator: AccountAuthenticator)
extends Controller
trait LoginController { this: Controller with
UserServiceComponent =>
object LoginController extends LoginController with
Controller with MongoDbUserServiceComponent
103. Loving Case Class And Constructors
case class Account(
id: Option[BSONObjectID] = None,
email: String,
creationDate: DateTime,
optin: Boolean = false,
optoutScenario: Option[DateTime] = None,
source: String = Account.DEFAULT_SOURCE,
deletionDate: Option[DateTime] = None)
Account(“chucknorris@gmail.com”,
creationDate = creationDate,
optin = true)
107. Once in production
– Creating accounts more easily
– Parsing CV on upload
– Can apply with the CV
– Follow applications
• And other awesome stuff built fast and
furiously !
Every developer I’ve spoken about it has already passed by it
Modulable
Scalable
REST oriented
API First
KPI
Stratégie de migration des données. Comment minimiser le delta ! Offline ! Beaucoup tester car les erreurs sont difficiles à corriger des semaines après.
Commencer le plus tôt possible. Minimiser l’adhérence à la base quand on communique avec des systèmes externes !
Zéro accès à la DB : Flexibilité => séparation du contrat (JSON) et de l’implémentation + non duplication de la logique.
Stats Github. Plus dynamique, feedback utilisateur….
Easy
Easy
Trop facile !
JSON généré, play reverse routing et hypermedia. Souligné que c’est une version simplifiée du JSON réel !
Un mot sur la gestion des erreurs plus tard.
Un mot sur la gestion des erreurs plus tard.
Un mot sur la gestion des erreurs plus tard.
Gérer les erreurs
URI simple : pas grand chose à dire sur les routes. Facile de se conformer aux URI style REST. Pas mis les noms de package pour avoir de la place.